Translation animation to hide

I need my list to hide and show using alternative strokes. Therefore, to hide the list on the left side of the screen, I use animation

Animation animation = new TranslateAnimation(-100, 0,0, 0); animation.setDuration(100); animation.setFillAfter(true); lv.startAnimation(animation); lv.setVisibility(0); 

and to display am using

 lv.setVisibility(View.VISIBLE); 

My problem is that viewing the list does not hide. He will go left and return again. I do not know how to completely hide the list to the left. Please help to achieve this.

+8
android android-listview android-view android-animation
source share
4 answers

Finally, I find the answer, and this is a very simple modification in coordinate values. And code

 Animation animation = new TranslateAnimation(0,-200,0, 0); animation.setDuration(2000); animation.setFillAfter(true); listView1.startAnimation(animation); listView1.setVisibility(0); 

Here I set a negative value for the second coordinating reason from o it moves two negative sides, which means that the view moves in two sides of the left left side.

+3
source share
 // To animate view slide out from left to right public void slideToRight(View view){ TranslateAnimation animate = new TranslateAnimation(0,view.getWidth(),0,0); animate.setDuration(500); animate.setFillAfter(true); view.startAnimation(animate); view.setVisibility(View.GONE); } // To animate view slide out from right to left public void slideToLeft(View view){ TranslateAnimation animate = new TranslateAnimation(0,-view.getWidth(),0,0); animate.setDuration(500); animate.setFillAfter(true); view.startAnimation(animate); view.setVisibility(View.GONE); } // To animate view slide out from top to bottom public void slideToBottom(View view){ TranslateAnimation animate = new TranslateAnimation(0,0,0,view.getHeight()); animate.setDuration(500); animate.setFillAfter(true); view.startAnimation(animate); view.setVisibility(View.GONE); } // To animate view slide out from bottom to top public void slideToTop(View view){ TranslateAnimation animate = new TranslateAnimation(0,0,0,-view.getHeight()); animate.setDuration(500); animate.setFillAfter(true); view.startAnimation(animate); view.setVisibility(View.GONE); } 
+20
source share

If you want to hide your view, use

 View.INVISIBLE // constant value 4 

or

 View.GONE // constant value 8 

You are currently using the value 0 , which is a constant View.VISIBLE value.

Suppose you want to hide a ListView after its animation?

But you show ListView immediately after starting the animation. Take a look at AnimationListener and hide ListView

 onAnimationEnd(...) 

For example:

 // assuming the listview is currently visible Animation animation = new TranslateAnimation(-100, 0,0, 0); animation.setDuration(100); animation.setFillAfter(true); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { lv.setVisibility(View.GONE); } @Override public void onAnimationRepeat(Animation animation) { } }); lv.startAnimation(animation); 
+3
source share

for a general understanding of what you don’t know, I found you another post that explains it very well! View and its animation work a little differently, as you would expect!

stack overflow

0
source share

All Articles