android - 使用图层列表不包裹父屏幕的背景可绘制

标签 android android-layout splash-screen layer-list

我正在尝试重新创建启动画面以符合 Google 标准。我尝试为我的启动画面创建一个可绘制的背景,我将在主题本身中设置它。但我正在寻找一种使位图与父级匹配的方法。

下面是我的可绘制代码:splash_screen_bg.xml

 <?xml version="1.0" encoding="utf-8"?> 
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
 <item android:gravity="center">
 <bitmap android:src="@drawable/logo_show" android:gravity="center" />
 </item>
 </layer-list>

这是我将此可绘制对象设置为 Activity 背景的代码:

 <style name="SpTheme" parent="SearchActivityTheme.NoActionBar"> 
 <item name="colorPrimaryDark">@color/colorAccentXDark</item>
 <item name="android:alertDialogTheme">@style/AlertDialogTheme</item> 
 <item name="android:windowBackground">@drawable/splash_screen_bg</item>
 </style>

最佳答案

您不能在位图中缩放图像。它不是 ImageView,因此它没有 scaleType 属性。您的图像将根据您放置的文件夹进行缩放(drawable-xdpi、drawable-nodpi、...)。您可以根据需要设置背景填充颜色。

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

<item
    android:drawable="@color/colorPrimary"/>

<item android:gravity="center">
    <bitmap android:src="@drawable/logo_show" android:gravity="center" />
</item>
</layer-list>

关于android - 使用图层列表不包裹父屏幕的背景可绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41759575/

相关文章:

android - 亚行 logcat : Increase the maximal message length

android - 如何在 Android 中制作 VideoView 预览 UI?

android - 带有 Dialogfragment 的 Activity 总是在中间

android - 如何将图像移动到 x、y 坐标与当前比例和填充的位置

jquery-mobile - 带有 javascript 的 jquery 移动闪屏

android - 自定义阵列适配器问题

android - Kotlin 变量被初始化两次

android - 如何使用 Android 双簧管库处理扬声器更改?

android - 在 Android 应用程序中正确加载资源(使用 openGL)

ios - 为什么我不能在 apache cordova/phonegap 应用程序中摆脱(或至少改变)iOS 上的默认启动画面?