簡體   English   中英

如何在Horizenatl滾動中使用Recycler視圖

[英]How to use Recycler view in Horizenatl Scrolling

我有一個具有線性布局和1個Recycler視圖的設計。線性布局包含一個表行,該表行的字段名稱為:課程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);

在您的布局中將水平滾動設置為父級。 對於回收站視圖,您可以在回收站視圖布局管理器中設置滾動屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM