Dan*_*Dan 10 android react-native
我有一个呈现可绘制对象的 Android 启动画面。当它通过冷启动打开时,我发现我的资产只是向上移动。
你可以在下面找到合适的代码,所有不必要的代码都被省略了。
这是轻微的变化:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
主活动.java
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashTheme);
super.onCreate(savedInstanceState);
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
我找到了解决方案:
您应该删除,ImageView因为您已经通过android:windowBackground. 同时删除android:background="@color/splash_background_color"从FrameLayout使它透明
顺便说一句,res/layout/launch_screen.xml如果您不打算在飞溅上绘制一些布局,则可以删除。
因为Activity不要打电话setContentView()
因为Fragment不要覆盖onCreateView()
没关系,Android 不需要为它们设置布局。
| 归档时间: |
|
| 查看次数: |
1199 次 |
| 最近记录: |