在/res/drawable/item.xml代码设计
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/logo1"
android:duration="150">
</item>
<item
android:drawable="@drawable/logo2"
android:duration="150">
</item>
<item
android:drawable="@drawable/logo3"
android:duration="150">
</item>
</animation-list>
在MainActivity中代码实现
在/res/drawable/item.xml代码设计
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/logo1"
android:duration="150">
</item>
<item
android:drawable="@drawable/logo2"
android:duration="150">
</item>
<item
android:drawable="@drawable/logo3"
android:duration="150">
</item>
</animation-list>
在MainActivity中代码实现
<span style="white-space:pre"> </span>ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setBackgroundResource(R.drawable.item);
AnimationDrawable ad = (AnimationDrawable) iv.getBackground();
ad.start();
布局res/layout/activity_main.xml代码实现
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" />
实现过程:1、在布局中定义ImageView视图,确定要实现的位置,可以使用同规格图片设计UI界面,这样更加美观;
<span style="white-space:pre"> </span> 2、设置item中图片切换资源,简单的动态视图实际上是利用同样式的图片,在某些地方的细微区别,在间隔时间中切换形成的视 觉效果,duration用来设置切换时间;
<span style="white-space:pre"> </span> 3、最后在MainActivity中进行代码实现,最后不要忘了start()启动。
……^_^简单的小demo,有时间可以测试下哦!
<pre name="code" class="html" style="font-size: 14.04px; font-weight: bold;">
<span style="white-space:pre"> </span>ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setBackgroundResource(R.drawable.item);
AnimationDrawable ad = (AnimationDrawable) iv.getBackground();
ad.start();
布局res/layout/activity_main.xml代码实现
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" />
实现过程:1、在布局中定义ImageView视图,确定要实现的位置,可以使用同规格图片设计UI界面,这样更加美观;
<span style="white-space:pre"> </span> 2、设置item中图片切换资源,简单的动态视图实际上是利用同样式的图片,在某些地方的细微区别,在间隔时间中切换形成的视 觉效果,duration用来设置切换时间;
<span style="white-space:pre"> </span> 3、最后在MainActivity中进行代码实现,最后不要忘了start()启动。
……^_^简单的小demo,有时间可以测试下哦!
<pre name="code" class="html" style="font-size: 14.04px; font-weight: bold;">