我在我的应用程序上运行了“调试GPU透支”工具,试图减少透支量。如下图所示,卡片视图就像一层额外的透支。我没有给我的其他布局提供任何额外的背景颜色或图像。
有没有办法解决这个问题?

<?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>发布于 2019-06-06 08:13:53
你的LinearLayout和RelativeLayout都有一个背景集#fff。移除它们,看看是否有帮助。
发布于 2019-06-06 08:18:41
这可能是一种误解,因为这不是什么“透支”,而是硬件层显示为绿色。如果你真的想禁用它,只需禁用View的硬件加速(甚至是整个应用程序):
cardView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);我的意思是,您可以尝试禁用它一次,以查看绿色覆盖消失,然后再次删除该指令,以便重新打开硬件加速。如果它可能延迟,这可能有另一个原因;例如:当RecyclerView和ScrollView组合在一起时,当它们被错误配置时,它们可能会严重延迟。
发布于 2019-10-23 07:28:24
我有一个简单的CardView布局,如下所示,我还观察到卡片边框上的透支。
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/dev_card_view"
android:layout_width="160dp"
android:layout_height="80dp"
android:layout_gravity="center"
card_view:cardCornerRadius="10dp"
card_view:contentPadding="10dp"
android:layout_margin="20dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</androidx.cardview.widget.CardView>通过将cardElevation设置为0dp,我能够消除透支。
card_view:cardElevation="0dp"https://stackoverflow.com/questions/36308238
复制相似问题