创建RecyclerViews时,何时使用CardViews与工具:listitem



我遇到了这个代码:

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
tools:listitem="@layout/recyclerview_item" />

其中tools:listitem是一个布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView"
style="@style/word_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_orange_light" />
</LinearLayout>

我的问题是,在创建recyclerews时,我们什么时候应该选择Cardview作为其项目,什么时候我们应该选择如上所述的布局?与另一个相比,一个提供了什么优势,或者它们是相同的(请注意,recyclereview_item布局XML没有任何Cardview标记,所以它们至少在字面上是不相同的(?

tools:listitem仅通过提供特定布局资源(无论是基于CardView的布局还是其他布局(来设置列表项的设计时预览。

您可以使用tools:listitem以及其他工具属性和@tools/sample资源来模拟组件的运行时或编译时行为,如布局、伪数据、可见性等。

这些属性不会以任何方式影响应用程序的运行时行为。

此外,您还可以阅读本教程中有关tools属性的内容。

至于卡片和常规布局,使用卡片作为容器有一些好处:卡片支持仰角、阴影、圆角,具有一致的视觉风格,同时支持不同的内容长度,不需要额外的操作。e.t.c

就我个人而言,如果我需要以平台一致的方式显示一些具有直接布局的列表项,我会使用基于CardView的布局。

最新更新