制作“从底部滑动"按钮(类似于快餐栏)(Android) [英] Making "slide from bottom" button (similar to snackbar) (Android)

查看:277
本文介绍了制作“从底部滑动"按钮(类似于快餐栏)(Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做些什么,但不知道如何做……那是一个由某些东西触发的按钮,它可以从屏幕底部滑动到某个位置.非常类似于小吃店的显示方式,不同之处在于它保持原位而不是消失,并且具有可单击"的属性.这不是从底部可拖动的面板,而是由某些东西自动触发的滑动面板.

there's something I want to do but don't know how... that would be a button that slides from the bottom of the screen to a certain position, triggered by something. Very similar to how snackbar show, with the difference that it stays in place instead of disappearing and has the property of being "clickable". This would NOT be a panel draggable from the bottom, but a panel that slides automatically triggered by something.

我该怎么做?

推荐答案

听起来像沿y轴的相当简单的动画,其起始值与屏幕的高度匹配(这样它就可以在屏幕外渲染) ,无论最终值是多少.下面的代码来自内存,但是应该可以工作.

Sounds like a fairly straightforward animation along the y axis, with a start value that matches the height of the screen (such that it renders just off screen), to whatever the final value is. Below code is from memory, but it should work.

要获取屏幕高度:

int getScreenHeight() {

    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    return displaymetrics.heightPixels;

}

并为视图设置动画(在这种情况下,为屏幕总高度的80%):

And to animate a view (in this case, to 80% of the total screen height):

void animateOnScreen(View view) {

    final int screenHeight = getScreenHeight();
    ObjectAnimator animator = ObjectAnimator.ofFloat(view, "y", screenHeight, (screenHeight * 0.8F));
    animator.setInterpolator(new DecelerateInterpolator());
    animator.start();

}

这篇关于制作“从底部滑动"按钮(类似于快餐栏)(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆