android - 背景渐变导致色带
问题描述
我尝试在我的应用程序的背景上做一些线性渐变,结果出现了色带。
我做了什么:
我创建了一个名为window_background_app.xml的形状
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="45"
android:endColor="#Fe005694"
android:startColor="#fe2D8ACC"
android:type="linear" />
</shape>
我在样式中使用了该形状以应用于背景:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@drawable/window_background_app</item>
</style>
</resources>
我在我的应用程序清单中使用了这种风格:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name="generic_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
问题
启动我的应用程序时,背景显示了一些带有渐变background_with_banding的条带
我在类似的问题(例如这个)中发现我应该:
- 尝试将背景抖动设置为 true。问题:现在不推荐使用抖动。
- 将 Pixelformat 设置为 PixelFormat.RGBA_8888。问题:这对我没有任何改变。
我遇到了这个问题:
- 一加 5t Api 28(真实设备)
- 三星 S8,Api 28(真实设备)
- Pixel 2 Api 24(模拟器)
- Pixel 2 Api 22(模拟器)
- 一个 Pixel C Api 27(模拟器)
条带未出现在:
- 三星 Galaxy J3 Api 22(真实设备)
- 三星 SM-T533 Api 22(真机)
问题
我不确定问题是由于 Android 版本的更新还是来自材料(或两者)的更新。我遇到的另一个问题是,我可以在网上找到的很多解决方案都相当陈旧(最近的解决方案是在 2014 年左右)。
所以我的问题是:
自 dither=true 和 pixelFormat=RGBA_8888 以来,是否有一些新的渐变色带解决方案?
解决方案
如果像素格式是 RGBA8888,我很确定抖动不会做任何事情,因此无法帮助视觉上相邻的 24 位 RGB 色调之间的条带。
这可能是 Android 的限制,它源于 OpenGL 的限制,即抖动仅适用于低于 32 位的位深度。OpenGL 是 Android 视图的支持实现。
因此,解决方案可能是使用 PNG 文件进行渐变,并且您的绘图程序已经内置了抖动功能。
推荐阅读
- google-sheets - 如何在 QUERY 的第二个参数中使用多个 TEXT 函数?
- ios - 如何将 Objective-C 代码添加到 Nativescript 插件?
- python - 同时旋转和分组列
- python - 从 pandas 数据帧构建频率字典而不循环
- php - PHP如何将另一个文件中的对象添加到不同JSON的数组中
- java - Ibinder 和 JobintentService
- spring-data-jpa - 多列上的 Spring Data JPA“或”运算符
- c - 在每个组件之后打印格式
- python - 如何在 Python3 中删除 HTML 标签
- html - 样式属性嵌套在一个 id 一个类和另一个属性中