How to make a buttons bar slide in from bottom upon clicking checkbox in ListView?

六月ゝ 毕业季﹏ 提交于 2019-12-01 09:22:42

You want to use Animation xml resources.

Here is an example of an Animation xml that will 'slide' the object up from the bottom of the screen to where ever its place is within your layout:

<?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>

You will put that in your res/anim folder then use this java code to animate your view:

slideUpIn = AnimationUtils.loadAnimation(this, R.anim.slide_up_in);
yourButtonBarView.startAnimation(slideUpIn);

You'll want to put the startAnimation call inside where you get the callback that your CheckBox has been checked.

Below is the runtime code implementation, modify accordingly if you need it for other purposes.

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!