【问题标题】:Cardview is not working with layertype softwareCardview 不适用于 layertype 软件
【发布时间】:2017-08-27 20:25:01
【问题描述】:

我需要绘制一些路径并将其显示在Recyclerview 下方。所以我更喜欢以下结构。

    <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"/>

我能够绘制我的视图并填充 recyclerview。好像没问题。

现在我的问题是我正在使用Cardviewrecyclerview 中显示项目。

以下是自定义单元格的代码。

    <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"/>

现在,由于我需要在画布中绘制长路径,我在“Srollview”中设置了layertype=Software,以便我的视图可以平滑滚动。

但是当我使用这个属性时,Cardview 没有设置corner-radiuselevation。如果从Scrollview 中删除此属性,则它可以工作,但我的观点滞后。

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 显示canvas 的sn-p 绘图内容。它可能会有所帮助
  • @Wizard 添加了屏幕截图
  • 我猜,两个分隔线之间的视图是CardView。对吗?
  • 是的。它显示平坦。无高程 + 无拐角半径

标签: android canvas scrollview cardview


【解决方案1】:

这是我从Android Open Source Project - Issue Tracker得到的

阴影仅支持硬件渲染。

除此之外,

如果您的应用程序仅使用标准视图,我认为启用硬件加速不会有太大影响。

Read here 关于何时使用或不使用硬件加速?
Read more 关于硬件加速的工作原理!

【讨论】:

  • Cardview 圆角半径也未设置。也是因为这个层类型?
  • @Beena 是的,我可以为您提供参考链接 - stackoverflow.com/questions/27599603/…
  • @Beena 但是您可以手动绘制阴影。我的意思是在画布上。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-15
  • 1970-01-01
  • 2018-01-13
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
相关资源
最近更新 更多