创建 RecyclerView 时何时使用 CardView 与 tools:listitem?
When to use CardViews vs tools:listitem when creating RecyclerViews?
我遇到了这段代码:
<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>
我的问题是,在创建recyclerviews时,我们什么时候应该选择Cardviews作为它的项目,什么时候我们应该选择上面提到的布局?
一个比另一个提供了哪些优势或者它们是否相同(请注意 recyclerview_item 布局 XML 没有任何 Cardview 标签,因此它们至少在字面上不相同)?
tools:listitem
仅通过提供特定布局资源为列表项设置设计时预览,无论是基于 CardView
的布局还是其他布局。
您可以使用 tools:listitem
和其他 tools attributes and @tools/sample
资源来模拟组件的运行时或编译时行为,例如布局、虚拟数据、可见性 e.t.c。
这些属性不会以任何方式影响应用程序的运行时行为。
此外,您可以阅读 this 关于 tools
属性的教程。
关于卡片与常规布局,使用卡片作为容器有一些好处:卡片支持高程、阴影、圆角并具有一致的视觉风格,同时支持不同的内容长度,无需额外操作 e.t.c
就个人而言,如果我需要以平台一致的方式显示一些具有简单布局的列表项,我会使用基于 CardView
的布局。
我遇到了这段代码:
<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>
我的问题是,在创建recyclerviews时,我们什么时候应该选择Cardviews作为它的项目,什么时候我们应该选择上面提到的布局? 一个比另一个提供了哪些优势或者它们是否相同(请注意 recyclerview_item 布局 XML 没有任何 Cardview 标签,因此它们至少在字面上不相同)?
tools:listitem
仅通过提供特定布局资源为列表项设置设计时预览,无论是基于 CardView
的布局还是其他布局。
您可以使用 tools:listitem
和其他 tools attributes and @tools/sample
资源来模拟组件的运行时或编译时行为,例如布局、虚拟数据、可见性 e.t.c。
这些属性不会以任何方式影响应用程序的运行时行为。
此外,您可以阅读 this 关于 tools
属性的教程。
关于卡片与常规布局,使用卡片作为容器有一些好处:卡片支持高程、阴影、圆角并具有一致的视觉风格,同时支持不同的内容长度,无需额外操作 e.t.c
就个人而言,如果我需要以平台一致的方式显示一些具有简单布局的列表项,我会使用基于 CardView
的布局。