首页 > 解决方案 > 如何使用 Recycler View 设置水平协调器布局

问题描述

我需要实现我的布局水平,但现在它是线性布局,我不知道我的错误在哪里,但我需要你的帮助来解决这个问题

<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/card_view_recycler_list"
        android:scrollbars="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.design.widget.CoordinatorLayout>

标签: xmlandroid-layoutandroid-recyclerviewandroid-coordinatorlayout

解决方案


在您的 java 类中输入以下代码:

 LinearLayoutManager lManager = new 
    LinearLayoutManager(getApplicationContext(),LinearLayoutManager.HORIZONTAL, false);
    lManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    mRecyclerView.setLayoutManager(lManager);

推荐阅读