If you just want a better transition view on GONE / VISIBLE rather than the default Android show/hide, I came across some simple trick to make a simple animation using TranslateAnimation class.
*Note: For a better transitioning, you can use animationlistener , and setVisibility onAnimationStart() or onAnimationEnd().
// View to be animate (I use ImageView as example here) ImageView imageView = (ImageView)findViewById(R.id.imageview);Below are the methods to set view from VISIBLE to GONE
// 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); }
0 nhận xét:
Đăng nhận xét