如何使用androidx.recyclerview.widget.RecyclerView
with tools:listitem
?
我有这样的布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recyclerViewActors"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
tools:listitem="@layout/list_item_actor"
tools:itemCount="5"
tools:orientation="horizontal"
tools:scrollbars="horizontal"
tools:spanCount="2"/>
but Design选项卡不显示预览:
如果我改变androidx.recyclerview.widget.RecyclerView
在这个布局中ListView
,预览有效:
从您的代码看来,您的 recyclerview 是 XML 的根元素,并且缺少 xmlns:tools 的引用
尝试使用另一个根元素作为约束布局,甚至只是布局,如以下示例所示谷歌向日葵应用程序 https://github.com/googlesamples/android-sunflower:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/plant_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingLeft="@dimen/margin_normal"
android:paddingRight="@dimen/margin_normal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:context="com.google.samples.apps.sunflower.GardenActivity"
tools:listitem="@layout/list_item_plant" />
</layout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)