アルファ アニメーション効果を含むスライド ショーを作成するコードを作成しました。画像リソースを配列に挿入し、id が呼び出されたときに特定の画像にアニメーションを適用しました。問題は、アニメーションが配列インデックス 1,3,5(R.drawable.b,R.drawable.d,R.drawable.f) に適用されないことです。コードを以下に示します。アクティビティ - 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"/>