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