Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translation animation for hiding View

I need my listview to hide and show using alternative touches. Hence for hiding the listview on the left side of the screen am using animation

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

and for displaying am using

lv.setVisibility(View.VISIBLE);

My problem is list view is not getting hide. It will go leftside and coming back again. I don't know how to hide listview to the left edge completely on touch. Please help in achieving this

like image 583
AndroidOptimist Avatar asked Sep 16 '13 09:09

AndroidOptimist


2 Answers

// 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);
}
like image 123
dipali Avatar answered Oct 27 '22 01:10

dipali


Finally i find the answer and it is very simple modification in co-ordinate values. And the code is

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

Here am setting negative value at second co-ordinate cause from o it is moving twowards negative side which means the view is moving twowards inner left side.

like image 20
AndroidOptimist Avatar answered Oct 27 '22 01:10

AndroidOptimist