在动画动画列表中的所有项目 [英] Animating all items in Animation-list
问题描述
我在动画列表和项规定的在我的image_list.xml图像(约10)的列表。而我在imgaes的影响作出了淡出一fade_in.xml文件。在code正常工作没有错误。
我有唯一的问题是,在淡入效果出现在第一图像中,但不是在image_list的其他物品。请告诉我一个方法,使这一切成为可能,使所有的图像都在褪色的效果,当他们appear.My code是:
image_list.xml
<?XML版本=1.0编码=UTF-8&GT?;
<动画列表的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:单稳=假>
<项目机器人:可绘制=@绘制/ SAMPLE1
机器人:时间=2000/>
<项目机器人:可绘制=@绘制/ SAMPLE2
机器人:时间=2000/>
<项目机器人:可绘制=@绘制/样本3
机器人:时间=2000/>
<项目机器人:可绘制=@绘制/ sample4
机器人:时间=2000/>
。 。 。
< /动漫列表>
ImagesActivity.java
公共无效onWindowFocusChanged(布尔hasFocus){
super.onWindowFocusChanged(hasFocus);
ImageView的img_change =(ImageView的)findViewById(R.id.images);
动画animationFadeIn = AnimationUtils.loadAnimation(这一点,R.anim.fade_in);
img_change.setBackgroundResource(R.drawable.image_list);
AnimationDrawable splashAnimation =(AnimationDrawable)img_change.getBackground();
如果(hasFocus){
img_change.setAnimation(animationFadeIn);
splashAnimation.start();
}}
添加进入和退出衰落持续时间之前启动AnimationDrawable
AnimationDrawable splashAnimation =((AnimationDrawable)iv.getBackground());splashAnimation .setEnterFadeDuration(500);
splashAnimation .setExitFadeDuration(500);animDrawable.start();
它为我工作。
快乐编码
I have a list of images(around 10) in my "image_list.xml" under "animation-list" specified with "item". And I have made one "fade_in.xml" file for fade in effect of the imgaes. The code works fine without errors.
The only problem I have is that the fade in effect appears in the first image but not in the other items of the image_list. Please tell me a way to make this possible so that all the images have fade in effect when they appear.My code is:
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>
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();
}}
Add enter and exit fade duration before start AnimationDrawable
AnimationDrawable splashAnimation = ((AnimationDrawable) iv.getBackground());
splashAnimation .setEnterFadeDuration(500);
splashAnimation .setExitFadeDuration(500);
animDrawable.start();
It Works for me.
Happy Coding
这篇关于在动画动画列表中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!