Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove CardView Overdraw

I ran the 'Debug GPU Overdraw' tool on my app in an attemtp to reduce the amount of overdraw. As seen in the image below, the cardview acts like an extra layer of overdraw. I haven't given any additional background colors or images to my other layouts.

Is there a way to solve this?

enter image description here

<?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>
like image 324
Joeri Verlooy Avatar asked Feb 14 '26 16:02

Joeri Verlooy


1 Answers

This might be a misconception, because this is not some "overdraw", but hardware layers are being displayed greenish. In case you really want to disable that, just disable the hardware acceleration for the View (or even the whole application, altogether):

cardView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

I mean, you could try to disable it once to see that the greenish overlay is gone and then remove that instruction again, in order to switch the hardware acceleration back on. If it may lag, this likely has another reason; for example: a RecyclerView in combination with a ScrollView may lag dearly, when they're mis-configured.

like image 190
Martin Zeitler Avatar answered Feb 17 '26 05:02

Martin Zeitler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!