可能的透支:根元素绘制背景,主题也绘制背景

时间:2017-02-13 07:32:42

标签: android xml android-layout android-view lint

我已经实现了可点击的Recyclerview项目并设置了android:background="?selectableItemBackground"点击效果,但在检查代码时我发现了这个lint问题。

皮棉警告: 可能的透支:根元素绘制背景?selectableItemBackground,主题也绘制背景

有什么想法解决这个警告吗?

我的xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?selectableItemBackground"
    android:clickable="true"
    android:orientation="vertical"
    android:padding="@dimen/row_padding">

    //...
</LinearLayout >

3 个答案:

答案 0 :(得分:7)

默认情况下,主题指定了android:windowBackground属性,顾名思义,指定启动活动的窗口背景。

这个棉绒警告只是告诉你:

  

喂!我看到你的主题已经应用了windowBackground,你的 root 布局在窗口背景上绘制了一些其他的drawable,使得窗口的背景毫无意义 - 从而不必要地过度绘制像素。

淘汰windowBackground会让lint不要抱怨:

<style name="AppTheme" parent="...">
    ...
    <item name="android:windowBackground">@null</item>
</style>

答案 1 :(得分:0)

您应该将纹波放在前景属性

答案 2 :(得分:0)

我会删除lint检查。对大多数应用程序进行x1透支是完全可以接受的。

有关Romain Guy的透支和表现的非常好的帖子:http://www.curious-creature.com/2012/12/01/android-performance-case-study/

在主题中设置<item name="android:windowBackground">@null</item>是错误的,因为它会删除您的活动启动动画(有关启动动画的详细信息,请参阅该帖子:https://cyrilmottier.com/2013/01/23/android-app-launching-made-gorgeous/)。你不应该这样做。

在Activity.onCreate()中设置getWindow().setBackgroundDrawable(null)是可行的,但您必须确保应用中的每个像素至少被绘制一次,因为您将无法再绘制背景。对于非常有限的收益来说,这是有潜在危险的。

相关问题