CardView和RecyclerView材料设计视图是什么?

时间:2015-09-23 13:23:49

标签: android material-design

我只是想知道他们是否真的是MD视图,因为他们的名字是 喜欢 android.support.v7.widget.CardView。

对于5.0及以上版本(类似于android.MaterialDesign.CardView),CardView是否有不同的包名?

2 个答案:

答案 0 :(得分:0)

compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.android.support:cardview-v7:23.0.1'

是的,他们是并且要将它们用于您的应用,您需要将这些依赖项添加到您的gradle文件中。

Recycler View

<android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

卡片视图

<android.support.v7.widget.CardView
        android:id="@+id/cv_custom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:elevation="2dp"
        card_view:cardElevation="2dp"
        card_view:cardUseCompatPadding="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/person_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/custom_event_name"
                android:ellipsize="marquee"
                android:gravity="bottom|end"
                android:maxLines="3"
                android:padding="8dp"
                android:scrollHorizontally="true"
                android:textColor="@color/textColorSecondary"
                android:textSize="18sp" />

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

答案 1 :(得分:0)

CardView基本上是支持库中包含的帮助程序小部件。即使在Android 5.0及更高版本中,您也必须使用android.support.v7.widget.CardView。但是,此小部件在5.0及以上版本中的绘制方式存在差异。

来自官方文件:

  

带有圆角背景和阴影的FrameLayout。

     

CardView使用L上的高程属性作为阴影并回落到a   旧平台上的自定义阴影实现。

     

由于圆角切割的昂贵性质,在平台上   在L之前,CardView不会剪切与其相交的子节点   圆角。相反,它添加填充以避免这种交集   (请参阅setPreventCornerOverlap(boolean)以更改此行为。)

     

在L之前,CardView会在其内容中添加填充并绘制阴影   那个地区。此填充量等于maxCardElevation +(1 -   cos45)*两侧的cornerRadius和maxCardElevation * 1.5 +(1 -   cos45)* cornerRadius在顶部和底部。

有关详细信息,请参阅Android Developers - CardView