【问题标题】:'Possible overdraw' when adding ripple effect to RecyclerView item向 RecyclerView 项目添加波纹效果时“可能过度绘制”
【发布时间】:2019-03-23 17:02:33
【问题描述】:

创建我的 RecyclerView 后,我注意到在尝试将涟漪效果应用于我的 RecyclerView 项目布局时出现此警告。为什么在各种教程中出现此警告android:background="?android:attr/selectableItemBackground" 是他们告诉人们用来获得连锁反应的东西?有谁知道应该怎么做才能消除这个警告?

可能的过度绘制:根元素使用同时绘制背景的主题绘制背景“?attr/selectableItemBackground”(推断主题为“@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>

Manifest 中定义的应用

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:theme="@style/AppTheme">

【问题讨论】:

    标签: java android xml android-recyclerview


    【解决方案1】:

    这是一个警告,在这种情况下,您应该忽略。

    linter 正在尝试查找您的 Activity 的主题指定 windowBackground 属性的情况,但 有一个指定 background 属性的根视图。在这些情况下,屏幕的整个背景将为windowBackground 绘制一次,然后为background 再次完全绘制。

    在这些实际情况下,您应该删除根视图的 background 属性并将 Activity 的主题的 windowBackground 设置为您在根视图上的内容。

    但你在这里没有这样做。首先,这只是一个itemView,而不是一个Activity。其次,涟漪效应通常不会遮挡视图“下方”的背景。

    【讨论】:

    • 还要记住 lint 是愚蠢的。它可能非常有用,但它不知道您要做什么。它只看到它面前的东西,而不一定看到用户面前的东西。
    猜你喜欢
    • 2015-09-05
    • 2015-09-04
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    • 2018-08-23
    • 2016-06-26
    • 1970-01-01
    相关资源
    最近更新 更多