How do I make the button bar slide down when I click on a list item in a ListView?

I have a listview with a custom list that populates the list with a checkbox and some text views. When the user selects the checkbox, I need a button bar to insert the image at the bottom of the screen and sit there. I made a button bar and can make it appear and disappear from the screen, changing its visibility to “gone” and “visible”, but this does not make them with the effect of sliding and sliding. How do I make these animations?

+3
source share
2 answers

You want to use xml animation resources .

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>

res/anim, Java- :

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

startAnimation , , CheckBox.

+25

, , .

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);
+2

Source: https://habr.com/ru/post/1781989/


All Articles