java - 向 RecyclerView 项目添加涟漪效果时“可能过度绘制”

标签 java android xml android-recyclerview

创建 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/

相关文章:

xml - 使用 schematron 验证大型 xml 文件

java - Java Swing 应用程序的一个很好的例子是什么?

java - 循环不工作

带有 PDF 加载的 Android webview

xml - Spring MVC Restful 406 Not Acceptable

java - fastxml jackson 使用 Pojo 创建嵌套 xml

java - 如何在 java eclipse 中导入/使用 StdDraw?

java - 如何将十进制数转换为 8 位二进制数?

java - 如何将 float 部分调整为下一个整数值

android - 需要在新 Activity 中显示结果