【发布时间】:2012-03-01 22:43:33
【问题描述】:
当我打开 droid 时,我不想要任何按钮,我只想自动显示一系列图像,每个图像在几秒钟后被另一个图像替换,一旦显示所有图像,它就会循环回第一个图片。我还是机器人开发的新手,我显然遗漏了一些东西。任何帮助将不胜感激。
我的 java 文件
public class Slidingpics2Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView image = (ImageView) findViewById(R.id.treat);
image.setBackgroundResource(R.drawable.theanime);
AnimationDrawable Anime = (AnimationDrawable) image.getBackground();
Anime.start();
}
}
我把 theanime.xml 文件放在 drawable 文件夹中
<?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/image1" android:duration="1000" />
<item android:drawable="@drawable/image2" android:duration="1000" />
<item android:drawable="@drawable/image3" android:duration="1000" />
<item android:drawable="@drawable/image4" android:duration="1000" />
</animation-list>
之后我的布局 main.xml 看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/treat"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</LinearLayout>
【问题讨论】:
标签: android animation slideshow drawable