0

我已经编写了代码来创建包含 alpha 动画效果的幻灯片。我已在数组中插入图像资源,并在调用特定图像时应用动画。问题是动画不适用于数组索引 1,3,5(R.drawable.b,R.drawable.d,R.drawable.f)。代码如下。Activity-Java代码---

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) {

}}

动画文件包含以下代码..

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

1 回答 1

0

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

于 2013-01-31T02:23:38.393 回答