【问题标题】:How to use Recycler view in Horizenatl Scrolling如何在水平滚动中使用 Recyclerview
【发布时间】:2016-07-31 17:24:25
【问题描述】:

我的设计具有线性布局和 1 个回收站视图。线性布局包含一个表格行,其字段名称为:课程 ID、课程标题、学分、状态和回收站视图用于显示行数据。我想设置水平滚动,以滚动 Recycler 视图和主要 xml 文件的其他设计。这是我的主要 XML 文件名 content_main.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:layout_marginTop="50dp"
    android:orientation="vertical"
    android:padding="5dp"
    tools:context="com.example.soulshunter.revandhv.MainActivity"
    tools:showIn="@layout/activity_main">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:padding="5dp"
            android:text="Registered Courses"
            android:textColor="#000000"
            android:textSize="24sp">

        </TextView>

    </TableRow>

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="#EEE"
        android:padding="16dp" />

    <TableRow

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:background="#00CC99">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:padding="5dp"
            android:text="Class"
            android:textColor="#000000"
            android:textSize="16sp">

        </TextView>

    </TableRow>

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TableRow

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ccffff">

            <TextView
                android:layout_width="102dp"
                android:layout_height="wrap_content"
                android:gravity="left"
                android:padding="5dp"
                android:text="Course Code"
                android:textColor="#000000"
                android:textSize="16sp">

            </TextView>

            <TextView
                android:layout_width="250dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="2dp"
                android:gravity="left"
                android:text="Course Title"
                android:textColor="#000000"
                android:textSize="16sp">

            </TextView>

            <TextView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:gravity="left"
                android:text="Credit Hours"
                android:textColor="#000000"
                android:textSize="16sp">

            </TextView>

            <TextView
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:gravity="left"
                android:text="Status"
                android:textColor="#000000"
                android:textSize="16sp">

            </TextView>

            <TextView
                android:layout_width="60dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:gravity="left"
                android:text="Action"
                android:textColor="#000000"
                android:textSize="16sp">

            </TextView>

        </TableRow>

    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp">

    </android.support.v7.widget.RecyclerView>

</LinearLayout>

我也在我的java文件中尝试过这个

mAdapter = new MoviesAdapter(crList);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext(),LinearLayoutManager.HORIZONTAL,false);
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mAdapter);

【问题讨论】:

    标签: java android xml android-layout


    【解决方案1】:

    在你的布局中将水平滚动设置为父级。对于回收站视图,您可以在回收站视图布局管理器中设置滚动属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-07
      • 2018-10-01
      • 2015-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-24
      相关资源
      最近更新 更多