我们怎样才能将动画一张图像用于另一张图像?

时间:2011-01-06 11:41:41

标签: android

如果我想要一个图像在另一个图像之后,我们如何使用动画 我有一些代码,但它没有工作

Context mContext;
 protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.animationdemo);
     Resources res = mContext.getResources();
     TransitionDrawable transition = (TransitionDrawable) res.getDrawable(R.drawable.transitiondrawable);
     ImageView image = (ImageView) findViewById(R.id.imgView);
     image.setImageDrawable(transition);
     transition.startTransition(1000);
 }

将一个xml文件migrationdrawable.xml文件制作成drawable文件夹

<transition xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/endoscope_"/>
  <item android:drawable="@drawable/endoscope_2"/>
</transition>

和一个布局文件animationdemo.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center">


<ImageView
 android:id="@+id/imgView"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">
 </ImageView>
</LinearLayout>

请告诉我错误的地方

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

您必须使用逐帧动画,请参阅:

http://www.twintechs.com/blog/?p=35