【发布时间】:2019-01-12 04:56:30
【问题描述】:
如何使用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,则预览有效:
【问题讨论】:
-
我复制了您的代码,当我在代码中添加此行
tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager"时,我遇到了同样的问题(看不到我的项目),因此如果不需要,您可以将其删除跨度> -
@crammeur,但我有这个问题,没有这条线
-
我在android studio的显示中看到这个
java.lang.ClassNotFoundException: androidx.recyclerview.widget.GridLayoutManager可以解释为什么你不能有显示。所以他无法显示,因为他没有找到这个 -
你使用
implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'还是implementation 'androidx.recyclerview:recyclerview:1.0.0-alpha1',因为当我使用alpha时我可以看到但当我更改时我看不到预览 -
尝试清理项目并重建它
标签: android android-recyclerview preview androidx android-tools-namespace