Search code examples
androidcanvasscrollviewcardview

Cardview is not working with layertype software


I need to draw some path and show it below Recyclerview. So i have preferred following structure.

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimaryDark"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark"
        app:contentInsetEnd="0dp"
        app:contentInsetLeft="0dp"
        app:contentInsetRight="0dp"
        app:contentInsetStart="0dp"
        app:layout_scrollFlags="scroll|enterAlways">

        <ImageView
            android:id="@+id/imageMenu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/app_name"
            android:padding="@dimen/d10dp"
            android:src="@drawable/ico_menu"/>

        <TextView
            android:id="@+id/toolbarTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/T_HEADER"
            android:textColor="@android:color/white"
            android:textSize="@dimen/d18sp"/>
        <ImageView
            android:id="@+id/imageAdd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:alpha="0.6"
            android:contentDescription="@string/app_name"
            android:padding="@dimen/d10dp"
            android:src="@drawable/ic_add_circle"/>


    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scrollGraph"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:paddingTop="@dimen/d20dp">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:id="@+id/layoutGraph"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"/>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerViewEvents"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layoutManager="LinearLayoutManager"/>
        </FrameLayout>

    </android.support.v4.widget.NestedScrollView>

<TextView
    android:id="@+id/textNoData"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="@string/TG_NO_DATA"
    android:textColor="@android:color/black"
    android:textSize="@dimen/d14sp"
    android:visibility="gone"/>

I am able to draw my views and fill recyclerview. It seems okay.

Now my issue is that I am using Cardview to display items in recyclerview.

Following is the code of custom cell.

    <android.support.v7.widget.CardView
        android:id="@+id/cardViewGraph"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        app:cardCornerRadius="@dimen/d5dp"
        app:cardElevation="@dimen/d5dp"
        app:cardUseCompatPadding="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:baselineAligned="false"
            android:orientation="horizontal"
            android:weightSum="4">

                <ImageView
                    android:id="@+id/imageTimeMap"
                 android:layout_width="0dp"
                         android:layout_height="match_parent"
                         android:layout_weight="1.8"
                    android:contentDescription="@string/app_name"
                    android:scaleType="centerCrop"
                    android:src="@drawable/bg_gray_placeholder"/>



            <LinearLayout android:layout_width="0dp"
                          android:layout_height="match_parent"
                          android:layout_weight="2.2"
                          android:orientation="vertical"
                          android:padding="@dimen/d3dp">

                <LinearLayout android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:gravity="center_vertical"
                              android:orientation="horizontal">

                    <TextView android:id="@+id/textTimeMapType"
                              android:layout_width="0dp"
                              android:layout_height="wrap_content"
                              android:layout_weight="1"
                              android:drawablePadding="@dimen/d3dp"
                              android:gravity="center_vertical"
                              android:textSize="@dimen/d10sp"/>

                    <ImageView
                        android:id="@+id/imageEditEvent"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/app_name"
                        android:padding="@dimen/d1dp"
                        android:src="@drawable/ico_edit_gray"/>

                </LinearLayout>


                <TextView android:id="@+id/textTargetHead"
                          android:layout_width="match_parent"
                          android:layout_height="0dp"
                          android:layout_marginTop="@dimen/d3dp"
                          android:layout_weight="1"
                          android:alpha="0.8"
                          android:ellipsize="end"
                          android:gravity="center_vertical"
                          android:maxLines="2"
                          android:textColor="@color/colorActivityHeader"
                          android:textSize="@dimen/d11sp"/>



            </LinearLayout>

        </LinearLayout>


    </android.support.v7.widget.CardView>


<TextView
    android:id="@+id/textDate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:gravity="center"
    android:maxLines="2"
    android:textSize="@dimen/d11sp"/>

Now, As i need to draw long path in canvas, I have set layertype=Software in 'Srollview' so my view scrolls smoothly.

But when i use this property, Cardview does not set corner-radius or elevation. If remove this property from Scrollview then it works but my view laggs.

Here is the screen shot of my graph

Any one could help me with this issue?


Solution

  • This is what I got from Android Open Source Project - Issue Tracker

    Shadows are only supported with hardware rendering.

    Apart from that,

    I don't think enabling Hardware acceleration affect very much if your application uses only standard views.

    Read here about when to use or not to use Hardware acceleration?
    Read more about how Hardware Acceleration works!