我尝试制作一个显示图像的介绍序列,等待三秒钟,然后用另一个替换图像,等待三秒钟,然后将布局更改为代表我的应用程序主菜单的另一个布局。 我使用postDelayed方法让我的应用程序等待。 但是,当我运行我的应用程序时,它只显示第一个图像,而不执行任何其他操作。
有什么建议吗?提前致谢
这是Java代码:
//Here is the intro sequence
introImg = (ImageView) findViewById(R.id.introImg);
introImg.postDelayed(new Runnable() {
@Override
public void run() {
introImg.setImageResource(R.drawable.title);
Log.w("myApp","replaced image");
}
}, 10000); //this will wait 3 seconds and then replace image
introImg.postDelayed(new Runnable() {
@Override
public void run() {
setContentView(R.layout.activity_main_menu);
Log.w("myApp","replaced layout");
}
}, 3000); //this will wait 3 seconds and then replace to main menu layout
这是布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/introImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/gj_games_android"
android:scaleType="fitXY" />
答案 0 :(得分:0)
尝试以下代码并告诉我它是如何进行的。
introImg = (ImageView) findViewById(R.id.introImg);
final Handler handler = new Handler();
final int delay1 = 3000; // adjust as needed
final Handler handler2 = new Handler();
final int delay2 = 3000; // adjust as needed // time here is 0
handler.postDelayed(new Runnable() {
public void run() {
introImg.setImageResource(R.drawable.title); // time here is 3
Log.w("myApp","replaced image");
handler2.postDelayed(new Runnable() {
public void run() {
setContentView(R.layout.activity_main_menu); // time here is 6
Log.w("myApp","replaced layout");
}
}, delay2);
}
}, delay1);
答案 1 :(得分:0)