【发布时间】:2016-07-18 10:07:02
【问题描述】:
我尝试在我的应用程序上运行“调试 GPU 过度绘制”工具,以减少过度绘制的数量。如下图所示,cardview 就像一个额外的透支层。我没有为其他布局提供任何额外的背景颜色或图像。
有没有办法解决这个问题?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="350dp"
card_view:cardCornerRadius="10dp"
android:layout_margin="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/container_top"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#fff"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:id="@+id/thumbnail_profile"
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="centerCrop"
android:layout_centerInParent="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp">
<TextView
android:id="@+id/created_by"
android:textSize="13sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/time_ago"
android:textSize="10sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp">
<ImageView
android:id="@+id/likes_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_like_red"/>
<TextView
android:id="@+id/likes_product"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:layout_marginTop="5dp"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="230dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/container_top"
android:scaleType="centerCrop"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#fff"
android:layout_alignParentBottom="true">
<TextView
android:id="@+id/brand_product"
android:textSize="24sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_marginLeft="5dp"
android:layout_alignParentTop="true"/>
<TextView
android:id="@+id/name_product"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
【问题讨论】:
-
发布项目布局文件
-
我编辑了问题并添加了xml布局文件
-
为什么这么复杂?它可以简化为this
-
通过去除上面和下面部分的背景颜色,我得到了更好的结果。谢谢!
-
@Selvin 我认为您应该发布要点作为答案。
标签: android performance