【发布时间】:2018-05-24 08:03:18
【问题描述】:
我想在Fixed 高度/区域内滚动ReyclerView。
用于演示用例的示例 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:id="@+id/ele_parent_ll"
android:layout_width="match_parent"
android:orientation="vertical"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/election_parent_sv"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/sample_id"
android:background="@color/white"
android:fitsSystemWindows="true">
<ImageView
android:contentDescription="@string/btn_youtube"
android:layout_width="match_parent"
android:layout_height="115dp"
android:id="@+id/election_banner"
android:background="@drawable/some_drawable"
android:adjustViewBounds="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mid_parent"
android:layout_marginLeft="@dimen/view_margin_10"
android:layout_marginRight="@dimen/view_margin_10"
android:layout_marginTop="@dimen/view_margin_10"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shaded_purple_new_local"
android:text="Layout heading"
android:textColor="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Choose one"
android:textColor="@color/icon_yellow"
android:textSize="13sp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/candidate_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/view_margin_10"
android:layout_marginLeft="@dimen/view_margin_10"
android:layout_weight=".5"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!--Sample Layout to make the screen scrollable for the example-->
<RelativeLayout
android:id="@+id/samp_RL"
android:layout_width="match_parent"
android:layout_height="200dp">
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
在这种情况下,RecyclerView 占用了它所需的空间,并且列表非常长,因此可滚动区域的总长度变长了,因此看到低于 RCV 的元素的可能性降低了。
为了解决这个问题,我想在固定区域内滚动RecyclerView,这样如果用户对此不感兴趣,他可以轻松查看RecyclerView下方的其他元素
- 当用户在 RCV 区域内滚动时,RCV 应该滚动。
- 当用户在 RCV 外滚动时,整个布局应该滚动
图片来自draw.io
我尝试过的:
- 使 RecyclerView 的高度保持不变:它被卡住了,根本不滚动。
- Making Recyclerview Fixed Height and Scrollable:也一样。它卡住了,根本不滚动。
- Scrollable NestedScrollViews inside RecyclerView:试过了,但无法与我目前的情况建立联系。
请告诉我这里缺少什么。
【问题讨论】:
标签: java android xml android-recyclerview