Previewing horizontal recyclerview in android studio

我与影子孤独终老i 提交于 2019-12-18 18:33:15

问题


I found out how to preview a list item by using

tools:listitem="@layout/my_item_layout"

Android studio however is previewing the recyclerview as a vertical list. Is there a way to tell Android Studio to display the layout preview in a horizontal fashion using LinearLayoutManager?


回答1:


Add a LayoutManager and set a horizontal orientation.

Here an example:

<android.support.v7.widget.RecyclerView
    android:id="@+id/homesRecyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layoutManager="android.support.v7.widget.LinearLayoutManager"
    android:layout_centerVertical="true"
    />



回答2:


If you are using androidx libraries:

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/homesRecyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
    android:layout_centerVertical="true"
    />



回答3:


the accepter answer works accurately. for androidx just use this in your recyclerView

app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" android:orientation="horizontal"




回答4:


Otherwise you can use in java file :

mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true));


来源:https://stackoverflow.com/questions/35681433/previewing-horizontal-recyclerview-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!