创建 RecyclerView 后,我注意到在尝试将波纹效果应用到 RecyclerView 项目布局时会出现此警告。为什么在各种教程中告诉人们使用 android:background="?android:attr/selectableItemBackground"
来获得链式 react 时会出现此警告?有谁知道应该做什么来消除这个警告?
Possible overdraw: Root element paints background '?attr/selectableItemBackground' with a theme that also paints a background (inferred theme is '@style/AppTheme')
RecyclerView 项目布局 (XML)
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tv_RVItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="?android:attr/textColorPrimary" />
styles.xml 中的相关主题
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
</style>
list 中定义的应用
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme">
最佳答案
这是一个警告,在这种情况下,您应该忽略它。
linter 尝试查找 Activity 主题指定 windowBackground
属性的情况,但还有指定 背景
属性。在这些情况下,将为 windowBackground
绘制一次屏幕的整个背景,然后为 background
再次完全绘制。
在这些实际情况下,您应该删除 Root View 的 background
属性,并将 Activity 主题的 windowBackground
设置为 Root View 上的内容。
但你不会在这里这样做。首先,这只是一个itemView,而不是一个Activity。其次,涟漪效果通常不会遮挡 View “下方”的背景。
关于java - 向 RecyclerView 项目添加涟漪效果时“可能过度绘制”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52881597/