简体   繁体   English

如何在Horizenatl滚动中使用Recycler视图

[英]How to use Recycler view in Horizenatl Scrolling

i have a design which have a linear layout and 1 Recycler view.The linear layout contains a table row having fields names as : Course ID, Course Title, Credit Hour, Status and Recycler view is to display rows data. 我有一个具有线性布局和1个Recycler视图的设计。线性布局包含一个表行,该表行的字段名称为:课程ID,课程标题,学分,状态和``回收者''视图用于显示行数据。 i want to set Horizental scrolling that scroll both Recycler view and other design of main xml file. 我想设置水平滚动,滚动滚动Recycler视图和其他主要xml文件设计。 Here is my main XML file names content_main.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>

and i had also tried this in my java file 我也在我的java文件中尝试过

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

set horizontal scroll as the parent in ur layout. 在您的布局中将水平滚动设置为父级。 And for recycler view u can set the scroll properties in ur recycler view layout manager. 对于回收站视图,您可以在回收站视图布局管理器中设置滚动属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM