在我的Android应用程序中,我有4个用xml动画的图像按钮:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/home1"
android:state_focused="true"
android:state_pressed="true" />
<item android:drawable="@drawable/home1"
android:state_focused="false"
android:state_pressed="true" />
<item android:drawable="@drawable/home" android:state_focused="true" />
<item android:drawable="@drawable/home2"
android:state_focused="false"
android:state_pressed="false" />
</selector>
当我点击按钮时,动画会运行但由于新活动打开得太快而无法正常显示。我希望看到完整的动画,我想我已经做了一个睡眠方法 但我完全不知道 这是我的动作按钮:
btn_photos.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Launching News Feed Screen
Intent i = new Intent(getApplicationContext(), PhotosActivity.class);
startActivity(i);
}
});
请帮助:)
答案 0 :(得分:0)
添加此代码
btn_photos.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Launching News Feed Screen
try{
Thread.sleep(2000);
}
catch( InterruptedException e) {}
Intent i = new Intent(getApplicationContext(), PhotosActivity.class);
startActivity(i);
}
});
根据您的愿望调整延迟。 =]
答案 1 :(得分:0)
创建一个Runnable并在onClickListener中启动它。给运行一个休眠时间。
Runnable viewPhotos = new Runnable() {
public void run() {
Thread.sleep(3000);
Intent i = new Intent(getApplicationContext(), PhotosActivity.class);
startActivity(i);
}
};
btn_photos.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Launching News Feed Screen
Thread thread = new Thread(null, viewPhotos, "ViewPhotos");
thread.start();
}
});