android xml中的Gif不起作用
您好,我想用xml创建gif动画。我分离了gif图像并使用了下面的代码 myxm.xmlandroid xml中的Gif不起作用,android,xml,gif,Android,Xml,Gif,您好,我想用xml创建gif动画。我分离了gif图像并使用了下面的代码 myxm.xml <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/a" android:dura
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/a" android:duration="100" />
<item android:drawable="@drawable/c" android:duration="100" />
<item android:drawable="@drawable/e" android:duration="100" />
</animation-list>
在我的布局中,我使用了代码
<ImageView
android:id="@+id/imageButton1"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:src="@anim/myxm" />
但它不适用于动画。这是用xml创建gif动画的正确方法吗?请先帮我谢谢:)您可以尝试以下方法
AnimationDrawable frameAnimation;
ImageView view;
view = (ImageView) findViewById(R.id.imageButton1);
// Setting myxm.xml as the background of the image view
view.setBackgroundResource(R.anim.myxm);
// Typecasting the Animation Drawable
frameAnimation = (AnimationDrawable) view.getBackground();
// Called when Activity becomes visible or invisible to the user
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
// Starting the animation when in Focus
frameAnimation.start();
} else {
// Stoping the animation when not in Focus
frameAnimation.stop();
}
}
xml看起来还可以,但要开始动画的java代码在哪里?