使用 drwable 对象对图像进行动画处理
我是 android 新手,如果有人可以帮助我,我将不胜感激。 我正在尝试对一系列图像(图片)进行动画处理。我读了一些相关内容,似乎一个好方法是使用可绘制对象。我的代码如下所示:
我有一个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>
最后,在我的活动中,我使用了可绘制对象来执行动画。像这样:
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平台上进行开发(这与此有什么关系吗?:))。
非常感谢
李皮
i am new to andriod and i would appreciate it if someone can help me.
i am trying to animate a sequence of images (pictures). i read a little about it and it seems that a good way to do it , is to use the drawable object. my code looks like this:
i have an animation.xml file with:
<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>
i defined an image view in the 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>
finally, in my activity, i used the drawable object to do the animation. like this:
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();
}
}
my problem is that i get only the first image instead of endless loop of images.
can anyone help with this?? i am doing the developement on android 2.1 platform (does this has anything to do with this? :)).
many thanks
lipi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你在这里遇到的唯一问题是你无法在 onCreate 方法中启动 AnimationDrawable 。
更多说明:http://developer.android.com/guide/topics /graphics/drawable-animation.html ,在文档的末尾...
I think the only problem you have here is that you can't start a AnimationDrawable in the onCreate method.
More explanation here : http://developer.android.com/guide/topics/graphics/drawable-animation.html , at the end of the document...
您可以使用逐帧动画来实现此目的。
您可以使用此链接
http://www.twintechs.com/blog/?p=35< /a>
You can use the FramebyFrame Animation for this.
You can use this link
http://www.twintechs.com/blog/?p=35