Issue
i want to ask that i want to make this animation as single image and wanted to apply some other view animation on it like move or alpha etc. how this can be done ? any idea ? simply i wanted to apply view animation on drawable animation.
i have some drawable like s1,s2,s3,s4 to s16 the XML is
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/s1" android:duration="200" />
<item android:drawable="@drawable/s2" android:duration="200" />
<item android:drawable="@drawable/s3" android:duration="200" />
<item android:drawable="@drawable/s12" android:duration="200" />
<item android:drawable="@drawable/s13" android:duration="200" />
<item android:drawable="@drawable/s14" android:duration="200" />
<item android:drawable="@drawable/s15" android:duration="200" />
<item android:drawable="@drawable/s16" android:duration="200" />
</animation-list>
and java code is
anim = (ImageView) findViewById(R.id.black);
anim.setBackgroundResource(R.drawable.smurf);
AnimationDrawable hello = (AnimationDrawable) anim.getBackground();
hello.start();
here smurf in drawable is the xml file for drawable animation.
Solution
we can do that animation but we have to maintain handler for that.
private int index = 0;
private Handler handler = new Handler();
private AnimationDrawable drawable;
Runnable runnable = new Runnable() {
@Override
public void run() {
imageView.setImageDrawable(drawable.getFrame(index));
index++;
if (index == drawable.getNumberOfFrames()) {
index = 0;
}
handler.postDelayed(runnable, drawable.getDuration(index));
}
};
in your onclick or where you want to start animation write like this:
handler.postDelayed(runnable, drawable.getDuration(index));
and your onDestroy()
remove the handeler call backs like this:
protected void onDestroy() {
super.onDestroy();
handler.removeCallbacks(runnable);
}
Answered By - balaji koduri
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.