我是 andriod 的新手,如果有人能帮助我,我将不胜感激。 我正在尝试为一系列图像(图片)制作动画。我读了一些关于它的内容,似乎一个很好的方法就是使用可绘制对象。我的代码如下所示:
我有一个 animation.xml 文件:
<animation-list xmlns:android = "http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/im1" android:duration="200" />
<item android:drawable="@drawable/im2" android:duration="200" /> </animation-list>
我在 main.xml 中定义了一个 ImageView :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> <ImageView
android:id="@+id/picView"
android:layout_width="500px"
android:layout_height="200px"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"> </ImageView> </RelativeLayout>
最后,在我的 Activity 中,我使用可绘制对象来制作动画。像这样:
public class animatePic extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView image = (ImageView) findViewById(R.id.picView);
image.setVisibility(ImageView.VISIBLE);
image.setBackgroundResource(R.drawable.animation);
AnimationDrawable imAnimate = (AnimationDrawable)image.getBackground();
imAnimate.start();
}
我的问题是我只得到第一张图片,而不是无限循环的图片。 有人能帮忙吗??我正在 android 2.1 平台上进行开发(这与此有什么关系吗?:))。
非常感谢
李皮
最佳答案
我认为您在这里遇到的唯一问题是您无法在 onCreate 方法中启动 AnimationDrawable。 更多解释在这里:http://developer.android.com/guide/topics/graphics/drawable-animation.html , 在文档的末尾...
关于android - 使用可绘制对象动画图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5701245/