Android 2.3: Grow/Shrink animation bug? -


for application, i'm trying add [grow/shrink + alpha change] animation each imageview in layout. managed animations working , have each of animations persist after they're done setting fillafter="true" both of xml files (grow.xml , shrink.xml). however, there seems weird animation bug causes unselected images grow , 'snap' normal size when set fillafter="true shrink.xml! let me explain how application works , give scenario becomes more clear:

initially, images have alpha levels set 50%. when click on particular image, grow 120% , alpha level become 100% ('light up' effect). when click on image, selected image shrink 100% , alpha level return 50% , selected image grow described previously.

in layout, have three, equal sized images placed in row. click first image, click second 1 click first 1 again. ok, no problems there. now, click on third image , weird snapping problem first image. idea how fix this?

i've tried:

  1. image.setalpha(...) avoid having set alpha level in shrink.xml calling fillafter="true", unfortunately that's api 11 call
  2. setting fillafter attribute of alpha tags true in shrink.xml
  3. calling image.startanimation(fadeout) right after shrink animation looks horrible.
  4. overriding onanimationend(), call never gets reached(??)

shrink.xml:

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fillafter="true"> <scale android:fromxscale="1.2" android:toxscale="1.0" android:fromyscale="1.2" android:toyscale="1.0" android:duration="300" android:pivotx="50%" android:pivoty="50%"/> <alpha android:fromalpha="1.0" android:toalpha="0.5" android:duration="300"/> </set>

grow.xml

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fillafter="true"> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:fromxscale="1.0" android:toxscale="1.20" android:fromyscale="1.0" android:toyscale="1.20" android:duration="300" android:pivotx="50%" android:pivoty="50%" /> <alpha android:fromalpha="0.5" android:toalpha="1.0" android:duration="300"/> </set>

fade_out.xml:

<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:startoffset="300" android:fromalpha="1.0" android:toalpha="0.5" android:fillafter="true"> </alpha>

main.xml:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center"> <imageview android:id="@+id/image1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="20dip" android:paddingright="20dip" android:src="@drawable/image1"/> <imageview android:id="@+id/image2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="20dip" android:paddingright="20dip" android:src="@drawable/image2"/> <imageview android:id="@+id/image3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="20dip" android:paddingright="20dip" android:src="@drawable/image3"/> </linearlayout>

test.java:

    public class test extends activity {     private view mselected;     public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      final animation fadeout = animationutils.loadanimation(this, r.anim.fade_out);     final animation grow = animationutils.loadanimation(this, r.anim.grow);     final animation shrink = animationutils.loadanimation(this, r.anim.shrink);      onclicklistener listener = new onclicklistener() {         @override         public void onclick(view v) {             // todo auto-generated method stub             if (mselected == v)                  return;              if (mselected != null)                  mselected.startanimation(shrink);              mselected = v;             mselected.startanimation(grow);                      }     };      imageview image1 = (imageview)findviewbyid(r.id.image1);     image1.startanimation(fadeout);     image1.setonclicklistener(listener);       imageview image2 = (imageview)findviewbyid(r.id.image2);     image2.startanimation(fadeout);     image2.setonclicklistener(listener);      imageview image3 = (imageview)findviewbyid(r.id.image3);     image3.startanimation(fadeout);     image3.setonclicklistener(listener); }} 

the problem shrink animation still assigned other views. when you're calling mselected.startanimation() starting animation object, attached other views, animate well. can create new instance of animation changing mselected.startanimation(shrink); to

mselected.startanimation(animationutils.loadanimation(test.this, r.anim.shrink)); 

which easy (though inefficient) way solve problem, or can manage animation cycle unassigning animations views (mselected.setanimation(null)).


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -