Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actual position of view not changing after setfillafter(true) in android animation

I am moving the view via this code, but the actual position of view is not changed, why

                TranslateAnimation ta = new TranslateAnimation(0, 0, Animation.RELATIVE_TO_SELF, -mbar4.getHeight());
                ta.setDuration(1000);
                ta.setFillAfter(true);
                v4.startAnimation(ta);
like image 320
Programmer Avatar asked Dec 28 '25 21:12

Programmer


1 Answers

up to version 3 (API 11) of android excluding , all animations don't really change the view , only the way it is shown . not only that, but i think they don't use the GPU at all.

in order to check it out , you can use a button and setOnClickListener for it , and see that no matter which animation you use , the click will work only on its original position and size.

here's a sample code of moving a view using the translateAnimation:

final int deltaXToMove=50;
TranslateAnimation translateAnimation=new TranslateAnimation(0,deltaXToMove,0,0);
int animationTime=1000;
translateAnimation.setDuration(animationTime);
translateAnimation.setFillEnabled(true);
translateAnimation.setFillAfter(true);
final Button b=(Button)findViewById(R.id.button);
translateAnimation.setAnimationListener(new AnimationListener()
  {
  @Override
  public void onAnimationEnd(Animation animation)
    {
    animation.setFillAfter(false);
    FrameLayout.LayoutParams par=(LayoutParams)b.getLayoutParams();
    par.leftMargin=deltaXToMove;
    b.setLayoutParams(par);
    }
...
b.startAnimation(translateAnimation);
like image 61
android developer Avatar answered Dec 31 '25 12:12

android developer