Android设计版面ListItem RecyclerView水平

eas*_*ese 13 xml android android-studio

我正在使用工具:listitem属性,通过recyclerview在设计版面中显示我的视图.问题是,它们总是出现在垂直列表中.有没有办法让设计版面编辑器水平显示它们?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:listitem="@android:layout/simple_list_item_checked"/>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我想要上面的图像,水平显示.在设计视图中.不在应用程序本身,我知道如何做到这一点.

小智 44

请检查此代码

   <android.support.v7.widget.RecyclerView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
Run Code Online (Sandbox Code Playgroud)

  • 事实证明,如果您将其与 tools:listitem="@layout/whatever" 结合使用,这将起作用。 (2认同)

Kev*_*tel 5

可行的完整示例:

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:orientation="horizontal"
    tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
    tools:listitem="@layout/view_item" />
Run Code Online (Sandbox Code Playgroud)

PS:如果您不使用AndroidX可以替换androidx.recyclerview.widget.LinearLayoutManager为。android.support.v7.widget.LinearLayoutManager