0
我寫過代碼來創建包含alpha動畫效果的幻燈片放映。我已將圖像資源插入到數組中,並在調用id時爲特定圖像應用動畫。 問題是動畫不適用於數組索引1,3,5(R.drawable.b,R.drawable.d,R.drawable.f)。代碼如下。 活動 - Java代碼---在Android中動畫淡入淡出
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"/>
它是全球性的變量。這就是爲什麼不初始化.. – Bharat