Android 如何使按钮栏在单击ListView中的复选框后从底部滑入?

Android 如何使按钮栏在单击ListView中的复选框后从底部滑入?,android,animation,slide,Android,Animation,Slide,我有一个带有自定义listadapter的listview,它用复选框和一些文本视图填充listview。当用户选中复选框时,我需要一个按钮栏从屏幕底部滑入视图并坐在那里。我已经制作了按钮栏,可以通过将其可见性更改为“gone”和“visible”使其在屏幕上显示和消失,但它不能通过滑入和滑出效果来实现这些。我如何让它做那些动画???你想用的 下面是一个动画xml示例,它将对象从屏幕底部“滑动”到布局中的任何位置: <?xml version="1.0" encoding="utf-8"?

我有一个带有自定义listadapter的listview,它用复选框和一些文本视图填充listview。当用户选中复选框时,我需要一个按钮栏从屏幕底部滑入视图并坐在那里。我已经制作了按钮栏,可以通过将其可见性更改为“gone”和“visible”使其在屏幕上显示和消失,但它不能通过滑入和滑出效果来实现这些。我如何让它做那些动画???

你想用的

下面是一个动画xml示例,它将对象从屏幕底部“滑动”到布局中的任何位置:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="100%p" android:toYDelta="0%p" android:duration="300"/>
</set>

您需要将startAnimation调用放在您得到复选框已选中的回调的内部

下面是运行时代码实现,如果出于其他目的需要,请进行相应修改

RelativeLayout rl = new RelativeLayout(this);
ImageButton btnBar = new ImageButton(this);

RelativeLayout.LayoutParams btnParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 80);

btnParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

btnBar.setLayoutParams(btnParams);
btnBar.setBackgroundColor(Color.RED); // test with red background

TranslateAnimation a = new TranslateAnimation(
                           Animation.RELATIVE_TO_PARENT, 0,
                           Animation.RELATIVE_TO_PARENT, 0,
                           Animation.RELATIVE_TO_PARENT, (float)100, 
                           Animation.RELATIVE_TO_PARENT, (float)0);

a.setDuration(1000);
btnBar.startAnimation(a); // add animation while start

rl.addView(btnBar);
setContentView(rl);

非常感谢。它部分地工作得很好。我之所以这么说,部分原因是我的buttonBarView的可见性最初设置为“gone”。选中复选框后,当我将其设置为“可见”时,屏幕底部将显示一个黑色条,稍后按钮条(取决于设置的翻译持续时间)将滑入该黑色条。这看起来并不顺利。我试图将buttonBarView顶部的y坐标设置为等于屏幕高度(以像素为单位),这样我就不必使用setVisibility()方法,但我不知道如何操作。有没有更好的办法?我不确定。我以前从未见过它做过这样的事。也许可以在使动画可见之前尝试启动动画。或者让它以View.INVISIBLE开始,而不是View.GONE。你是如何创建页脚的?
RelativeLayout rl = new RelativeLayout(this);
ImageButton btnBar = new ImageButton(this);

RelativeLayout.LayoutParams btnParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 80);

btnParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

btnBar.setLayoutParams(btnParams);
btnBar.setBackgroundColor(Color.RED); // test with red background

TranslateAnimation a = new TranslateAnimation(
                           Animation.RELATIVE_TO_PARENT, 0,
                           Animation.RELATIVE_TO_PARENT, 0,
                           Animation.RELATIVE_TO_PARENT, (float)100, 
                           Animation.RELATIVE_TO_PARENT, (float)0);

a.setDuration(1000);
btnBar.startAnimation(a); // add animation while start

rl.addView(btnBar);
setContentView(rl);