【问题标题】:Linear Layout - Only RecyclerView scrolls线性布局 - 只有 RecyclerView 滚动
【发布时间】:2015-07-03 13:41:25
【问题描述】:

我试图滚动整个页面,但只有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>

这是一张图片:

【问题讨论】:

  • LinearLayout 不滚动

标签: android scroll android-linearlayout android-recyclerview


【解决方案1】:

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

但如果你这样做,那么你的滚动可能会中断,因为你在 ScrollView 中有一个 RecyclerView

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

【讨论】:

  • 同意 Dimitar,您永远不应该将 ScrollView 与 ListView 一起使用,因为 ListView 负责自己的滚动。最重要的是,这样做会破坏 ListView 中处理大型列表的所有重要优化,因为它有效地强制 ListView 显示其整个项目列表以填充 ScrollView 提供的无限容器。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多