有没有办法在Android Studio编辑器中显示RecyclerView内容的预览?

twe*_*per 270 android android-studio android-recyclerview android-tools-namespace

当我将RecyclerView添加到布局时,它显示为空白屏幕.有没有办法,比如通过tools名称空间,来显示RecyclerView内容的预览?

Phi*_*vid 601

@oRRs是对的!

我正在使用Android Studio 1.4 RC2,您现在可以指定任何自定义布局.

我尝试了一个自定义的CardView,它的工作原理.

tools:listitem="@android:layout/simple_list_item_checked"
Run Code Online (Sandbox Code Playgroud)

  • @sajad尝试这个应用程序:layoutManager ="GridLayoutManager"工具:listitem ="@ layout/layout_list_item_select_seat"app:spanCount ="5" (21认同)
  • 正确,使用自定义持有者XML布局测试:`tools:listitem ="@ layout/holder_recorded"`.工作良好. (9认同)
  • 如果您还希望将方向设置为水平,您可以:`tools:orientation ="horizo​​ntal"` (4认同)
  • 除了指定`tools:orientation="horizo​​ntal"` 或`android:orientation="horizo​​ntal"` 之外,我还必须按照https://stackoverflow 指定`app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"` .com/questions/35681433/previewing-horizo​​ntal-recyclerview-in-android-studio (3认同)
  • 有没有办法在网格模式下预览? (2认同)

yoA*_*ex5 124

tools namespace支持设计时功能(例如在片段中显示哪种布局)或编译时行为(例如应用于XML资源的缩小模式)这是一个非常强大的功能,正在开发并允许您不能每次编译代码是时候看到变化了

GridLayoutManager示例

<!-- AndroidX -->
<androidx.recyclerview.widget.RecyclerView
    tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager"

<!-- support -->
<android.support.v7.widget.RecyclerView
    tools:layoutManager="android.support.v7.widget.GridLayoutManager"

    <!-- common -->
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:itemCount="5"
    tools:listitem="@layout/item_video"
    tools:orientation="horizontal"
    tools:scrollbars="horizontal"
    tools:spanCount="2" />
Run Code Online (Sandbox Code Playgroud)

引入的另一个很酷的功能Android studio 3.0是通过工具属性预定义数据,以便使用可视化的布局结构tools:text="@tools:sample/last_names".例如,您的预览将如下所示在此输入图像描述

请在此处阅读更多内容 -
https://developer.android.com/studio/write/tool-attributes.html
https://youtu.be/Hx_rwS1NTiI?list=PLWz5rJ2EKKc-odHd6XEaf7ykfsosYyCKp&t=408
https://android.jlelse.eu/Android的工具-属性-列表项样本数据岩石,bbf49aaa9f07

  • 这应该被标记为答案,因为它详细且与RecylerView兼容。ListViews现已不再使用。 (2认同)

Âng*_*tto 7

首先,在项目 XML 中添加以下行,以便在编辑项目时预览列表:

tools:showIn="@layout/activity_my_recyclerview_item"
Run Code Online (Sandbox Code Playgroud)

然后,在 RecyclerView XML 中添加以下行以预览您的项目在列表中的外观:

tools:listitem="@layout/adapter_item"
Run Code Online (Sandbox Code Playgroud)