我在"image_list.xml"下的"dynamic-list"下面有一个图像列表(大约10个),用"item"指定.我已经制作了一个"fade_in.xml"文件,用于淡化imgaes的效果.代码工作正常,没有错误.
我唯一的问题是淡入效果出现在第一张图片中,但不出现在image_list的其他项目中.请告诉我一种使这种方式成为可能的方法,以便所有图像在出现时都有效.我的代码是:
image_list.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/sample1"
android:duration="2000"/>
<item android:drawable="@drawable/sample2"
android:duration="2000"/>
<item android:drawable="@drawable/sample3"
android:duration="2000"/>
<item android:drawable="@drawable/sample4"
android:duration="2000"/>
. . .
</animation-list>
Run Code Online (Sandbox Code Playgroud)
ImagesActivity.java
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
ImageView img_change = (ImageView) findViewById(R.id.images);
Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in);
img_change.setBackgroundResource(R.drawable.image_list);
AnimationDrawable splashAnimation = (AnimationDrawable) img_change.getBackground();
if(hasFocus) {
img_change.setAnimation(animationFadeIn);
splashAnimation.start();
}}
Run Code Online (Sandbox Code Playgroud) android android-image android-animation android-layout android-imageview