我有一个Android启动屏幕,它渲染了一个drawable。当通过冷启动打开时,我发现我的资源只是向上移动。
下面是相关的代码,所有不必要的代码都已省略。
这里是轻微的位移:
SplashActivity.java
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashTheme);
super.onCreate(savedInstanceState);
}
res/drawable/background_splash.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item android:drawable="@color/splash_background_color"/>
<item
android:gravity="center"
>
<bitmap
android:src="@drawable/x150"/>
</item>
</layer-list>
res/layout/launch_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/splash_background_color">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/background_splash"
/>
</FrameLayout>
res/values/styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
</resources>
FrameLayout
中添加android:fitsSystemWindows="true"
。 - Taras Parshenkoandroid:fitsSystemWindows="true">
中。 - DanSplashActivity.java
中导入AppCompatActivity
的代码行吗? - hashinclude72