简体   繁体   中英

fade in animation in android

I have written the code to create slide show that contains the alpha animation effect. I have inserted the image resource in the array and apply the animation for particular image when it id called. The Problem is that the animation is not applied for array index 1,3,5(R.drawable.b,R.drawable.d,R.drawable.f). The code is given below. Activity- Java code---

public class DivyeshAnimationActivity extends Activity implements AnimationListener {

int imagearray[]={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e,R.drawable.f};


ImageView img,img1;

Animation anim,anim1;
int counter;
int k;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    img=(ImageView)findViewById(R.id.img);
    anim=AnimationUtils.loadAnimation(DivyeshAnimationActivity.this,
            R.anim.anim);
    img.setImageResource(imagearray[counter]);
    img.startAnimation(anim);
    anim.setAnimationListener(this);
    }

public void onAnimationEnd(Animation animation) {
    if(counter==imagearray.length-1)
    {
        counter=0;
    }
    else
    {
        counter++;  
    }
        img.setImageResource(imagearray[counter]);
        img.startAnimation(anim);   
}
public void onAnimationRepeat(Animation animation) {


}
public void onAnimationStart(Animation animation) {

}}

THe anim file contains the following code..

<alpha 
    android:fromAlpha="0"
    android:toAlpha="1"
    android:duration="2000"/>

我注意到的唯一问题是变量计数器未初始化

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM