如何通过tools:listitem使用androidx.recyclerview.widget.RecyclerView?

克塞尼亚

如何搭配androidx.recyclerview.widget.RecyclerView使用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"/>

但是“设计”选项卡不显示预览:

在此处输入图片说明

而且,如果我androidx.recyclerview.widget.RecyclerView将此布局更改ListView,则预览工作正常:

在此处输入图片说明

铁托·雷森德

从您的代码看来,您的recyclerview是XML的根元素,并且缺少xmlns:tools的引用。

尝试使用另一个根元素,作为约束布局,或者甚至按照google sunflowerapp的示例进行布局

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

这是什么“ RecyclerView没有LayoutManager androidx.recyclerview.widget.RecyclerView”错误?

androidx.recyclerview.widget.RecyclerView 无法转换为 android.widget.LinearLayout

如何在androidx.recyclerview.widget中使用androidx.recyclerview.selection。或者如何在Android中使用Kotlin在recyclerview中选择项目?

如何解决:空对象引用上的“boolean androidx.recyclerview.widget.RecyclerView.hasFixedSize()”

Android RecyclerView:尝试在空对象引用上调用虚拟方法 'void androidx.recyclerview.widget.RecyclerView.setAdapter()

Android如何使用androidx.recyclerview.widget.DiffUtil应用多个过滤器

尝试从空对象引用中读取字段“ android.view.View androidx.recyclerview.widget.RecyclerView $ ViewHolder.itemView”

java.lang.NullPointerException:尝试调用虚拟方法'android.view.View androidx.recyclerview.widget.RecyclerView

遇到尝试在空对象引用上调用虚拟方法“void androidx.recyclerview.widget.RecyclerView.setHasFixedSize(boolean)”

使用 RecyclerView 并调用 android.support.v7.widget.RecyclerView.setHasFixedSize(boolean) 时应用程序崩溃

RecyclerView ItemDecoration 被 AndroidX 破坏

我如何使用 RecyclerView

如何使卧式recyclerview项目显示在recyclerview的底部

对不同的 RecyclerView 使用相同的 RecyclerView.Adapter?

Recyclerview滚动通过FAB

如何窥视RecyclerView + PagerSnapHelper

如何对recyclerView进行排序

如何编辑RecyclerView数据

如何制作双向RecyclerView?

如何分类Recyclerview?

如何禁用RecyclerView滚动?

如何使RecyclerView平滑滚动?

如何创建按钮的 RecyclerView

如何从Recyclerview隐藏Cardview

如何从BroadcastReceiver更新RecyclerView?

如何获取RecyclerView位置

如何隐藏 RecyclerView 项目

如何正确填充RecyclerView?

使用CardView的RecyclerView