我有一个带有启动屏幕的应用程序,启动屏幕在小型设备上看起来不错,但在大型平板电脑(模拟器)上看起来很糟糕。所以我把背景改成了wrap_content
。但它看起来与屏幕的一侧对齐,有人可以告诉我一种将背景图像居中的方法吗?这是我的splash.xml-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/splash">
</LinearLayout>
我正在为我的活动使用背景图像。首先在 styles.xml 中创建一个主题:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
然后创建一个名为background_splash.xml的新drawable
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorWhite"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/logo_splash"/>
</item>
</layer-list>
然后将您的 Activity 设置为在 AndroidManifest.xml 中使用此主题:
<activity android:name="SplashActivity" android:theme="@style/SplashTheme" >
这对我有用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)