【发布时间】:2019-12-30 16:25:30
【问题描述】:
我想为调整到手机宽度的整个应用创建垂直重复的背景。
我的位图是:
资源/drawable/repeating_bitmap.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/app_bg_003_phone"
android:gravity="fill_horizontal"
android:tileModeY="repeat" />
我的风格是:
资源/值/style.xml
<style name="AppTheme" parent="BaseTheme">
<item name="android:windowBackground">@drawable/repeating_bitmap</item>
</style>
我的问题就在这里:
如您所见,不是整个图像,而是边缘被拉伸,很奇怪。
如何实现水平拉伸和垂直重复背景? 我在位图上使用了正确的标志... (android:gravity="fill_horizontal" android:tileModeY="repeat")
如果这可以帮助我附加我重复的原始图像(mdpi)
我想使用重复位图来节省内存。这也是我目前唯一可用的 jpeg 模式。
更新
现在我知道为什么只有边缘被拉伸了:来自文档: https://developer.android.com/reference/android/graphics/drawable/BitmapDrawable
“启用平铺模式时忽略重力。默认值为“禁用”。”
这意味着当我得到 tileModeY="repeat" 时,默认情况下为 tileModeX,因为我整体启用了 tile 模式,必须是 tileModeX="clamp",即:
"clamp 复制边缘颜色。"
有什么想法可以同时使用 tileMode 和重力吗?我试图将此位图插入到重力为“fill_horizontal”的另一个视图中。可惜没有成功。
【问题讨论】:
-
我面临着完全相同的问题。当我启用 tileModeY 时,重力几乎被忽略了。
标签: android bitmap repeat tile gravity