将位图重力设置为底部离开奥利奥中的屏幕图层列表 [英] setting bitmap gravity as bottom goes off the screen layer-list in Oreo
问题描述
我的初始视图为 xml 文件,如下所示.这段代码使用目标版本作为 api 19 (kitkat) 工作得非常好,但是一旦我将目标更改为 Oreo,底部的 splash_text 的一半就会离开屏幕.为什么会发生这种情况,我该如何解决?针对 kitkat ,飞溅的文字就在底部.我试图在位图上添加 layout_margin 但它也没有帮助我.
I have my splash view as xml file like below. this code works perfectly fine using target version as api 19 (kitkat) but once I change using target as Oreo,half of the splash_text at the bottom goes off the screen. why is that happening and how can I fix it? targeting kitkat , splash text is perfectly right at the buttom. I tried to add layout_margin on bitmap but it didnt help me either.
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item>
<color android:color="@color/background_material_light"/>
</item>
<item>
<bitmap
android:src="@drawable/ic_launcher"
android:tileMode="disabled"
android:gravity="center"/>
</item>
<item>
<bitmap
android:src="@drawable/splash_text"
android:tileMode="disabled"
android:gravity="bottom"
/>
</item>
</layer-list>
推荐答案
当您设置位图的重力时会发生这种情况.这就像位图元素的该属性的行为将其推送到屏幕之外.因此,通过在 item 元素上添加一些边距将其推入屏幕内.
This happens when you set the gravity of the bitmap. It's just like the behavior of that attribute for bitmap element pushes it outside the screen. Therefore, by adding some margin on the item element to pushes it inside the screen.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorPrimaryDark" />
<item android:top="25dp">
<bitmap
android:gravity="top"
android:src="@drawable/your_image" />
</item>
<item android:bottom="75dp">
<bitmap
android:gravity="bottom"
android:src="@drawable/your_image" />
</item>
</layer-list>
这篇关于将位图重力设置为底部离开奥利奥中的屏幕图层列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!