线性布局 - 仅循环使用RecyclerView

时间:2015-07-03 13:41:25

标签: android scroll android-linearlayout android-recyclerview

我正在尝试滚动所有页面,但只有RecyclerView在那个浅蓝色区域滚动?我能做什么?这是我的xml。当我尝试滚动时,只有RecyclerView在其区域滚动。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_color">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="200dp">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:id="@+id/tab_user_image"
        android:scaleType="centerCrop"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="11pt"
        android:textStyle="bold"
        android:textColor="@color/tabsScrollColor"
        android:layout_marginTop="160dp"
        android:layout_marginLeft="24dp"
        android:id="@+id/tab_user_name"
        />
    </RelativeLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingTop="6dp"
        android:paddingBottom="10dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:layout_marginTop="10dp">
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textColor="@color/tabsScrollColor"
            android:layout_weight="0.25"
            android:textSize="8pt"
            android:layout_gravity="center_vertical"
            android:id="@+id/tab_user_follower"
            />
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:layout_gravity="center_vertical"
            android:gravity="center_horizontal"
            android:id="@+id/tab_user_following"
            android:textColor="@color/tabsScrollColor"
            android:textSize="8pt"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:layout_gravity="center_vertical"
            android:gravity="right"
            android:textColor="@color/tabsScrollColor"
            android:id="@+id/tab_user_point"
            android:textSize="8pt"
            android:paddingRight="8dp"/>
        <ImageView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:src="@drawable/star_smooth"/>

    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tab_user_recycler_view"
        />



    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fabSize="normal"
        android:id="@+id/tab_user_fab"
        android:layout_gravity="bottom|right"
        android:layout_margin="16dp"
        android:transitionName="@string/fab_transition_name"
        android:src="@drawable/fab_image"
        app:layout_anchor="@id/tab_user_recycler_view"
        app:layout_anchorGravity="bottom|right|end"
        app:backgroundTint="@color/app_color"
        />
</LinearLayout>

以下是图片的外观:

1 个答案:

答案 0 :(得分:1)

需要通过将LinearLayout包裹在ScrollView中来启用滚动。

但如果您这样做,那么由于RecyclerView中有ScrollView,您的滚动可能会中断。

最简单的一个是您的顶部图像和文本要包装到单独的单元格(渲染器)中,然后像回收器视图中的任何其他单元格一样添加它。