【发布时间】:2015-01-08 10:24:28
【问题描述】:
我有一个使用这种布局的启动活动,它只在中心显示一个图像。
但是,只显示空白的黑页,然后跳转到目标类。
问题是启动活动没有像activity_launch.xml中那样显示...这是什么问题?
activity_launch.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".app.LaunchActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical|center_horizontal"
android:background="#0064B0">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo_property_finder" />
</LinearLayout>
java:
public class LaunchActivity extends BaseActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent intent = new Intent(this, HomeActivity.class);
startActivity(intent);
this.finish();
}
}
}
这是 LaunchActivity 的清单: 清单:
<application
android:name=".app.BaseApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyTheme">
<!-- App Pages -->
<activity
android:name=".app.LaunchActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
... Other activities
</application>
我的主题:
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:homeAsUpIndicator">@drawable/button_back</item>
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
【问题讨论】:
-
你想做什么??你想显示 LaunchActivity 1 秒然后启动 HomeActivity??
-
是的,但这不是问题。我的问题是布局只是空白页,而不是activity_launch.xml中写的
-
那是因为您在 onCreate 方法中执行了 Thread.sleep :只有在完全调用 onCreated 后才会创建接口。把你的睡眠放在外面