【发布时间】:2018-07-21 20:49:26
【问题描述】:
您好,我是使用 AS 进行 Android 编程的新手。这应该是一个常见/简单的问题,但到目前为止我还没有找到解决方案。
我在activity_main.xml 中为平板电脑创建left_ 和right_fragments 标签,我想在right_fragment 中设置背景颜色(暂时设置为#ffffff 并保持left_fragment 为默认值)。然后Android Lint 警告我在right_fragment 上得到了Overdraw: Painting regions more than once:
我尝试创建一个新主题:
<style name="NoBgTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:windowBackground">@null</item>
</style>
并将android:theme="@style/NoBgTheme"添加到right_fragment.xml,但没有成功。
Screenshot of this app w/ Debug GPU Overdraw enabled.
如果我在AndroidManifest.xml 中将android:theme= 从"@style/AppTheme" 更改为"@style/NoBgTheme",它可以工作,但所有其他布局都失去了背景。
知道如何修复这个 OVERDRAW 吗?提前谢谢。
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal">
<fragment
android:id="@+id/left_fragment"
android:name="jerryc05.fragmenttest.LeftFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="@+id/right_fragment"
android:name="jerryc05.fragmenttest.RightFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
left_fragment.xml 非常简单,我们可以忽略它。
right_fragment.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:theme="@style/NoBgTheme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff">
<TextView
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="This is right fragment"
android:textSize="20sp"
tools:ignore="HardcodedText" />
</LinearLayout>
AndroidManifest.xml 保持不变。
MainActivity.java 保持不变。
【问题讨论】:
标签: android layout fragment gpu-overdraw