我是andriod的新手,如果有人可以帮助我,我将不胜感激。 我试图动画一系列图像(图片)。我阅读了一些关于它的内容,看来这是一个很好的方法,就是使用drawable对象。我的代码看起来像这样:
我有一个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中定义了一个图像视图:
<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>
最后,在我的活动中,我使用了drawable对象来做动画。像这样:
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平台上进行开发(这与此有什么关系吗?:))。
非常感谢梨皮
答案 0 :(得分:1)
我认为你遇到的唯一问题是你无法在onCreate方法中启动AnimationDrawable。 这里有更多解释:http://developer.android.com/guide/topics/graphics/drawable-animation.html,在文档末尾......
答案 1 :(得分:0)