0
我的代碼的問題是,它先顯示圖像,然後顯示動畫(淡入)。首先,圖像在屏幕上顯示大約一秒鐘,然後淡入的相同的圖像發生。請幫助。 這是代碼:應用程序首先顯示圖像,然後顯示動畫
public class LoginActivity extends Activity {
private Animation translate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
final ImageView image = (ImageView) findViewById(R.id.image);
Animation translate = AnimationUtils.loadAnimation(this, R.anim.translate);
image.startAnimation(translate);
final int[] imageArray = {R.drawable.agra, R.drawable.bang,
R.drawable.mumbai
};
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
int i = 0;
public void run() {
image.setImageResource(imageArray[i]);
i++;
if (i > imageArray.length - 1) {
i = 0;
}
handler.postDelayed(this, 4000);
}
};
handler.postDelayed(runnable, 4000);
}
}
,這是動畫文件translate.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="4000"
android:fillAfter="true"
android:fromAlpha="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:repeatCount="-1"
android:toAlpha="1">
</alpha>
感謝您的快速回答,但問題仍然存在 –