gpt4 book ai didi

android - CoordinatorLayout 中的 RelativeLayout 不滚动

转载 作者:行者123 更新时间:2023-12-05 00:06:55 30 4
gpt4 key购买 nike

我的 CoordinatorLayout 中有一个 RelativeLayout(如下所示)。另请注意,在 RelativeLayout 中我有一个 RecyclerView

但是,当我滚动时,我只能在 RecyclerView 上滚动,只有屏幕的 RecyclerView 部分会实际滚动。如果我尝试在 RecyclerView 上方的布局上滚动,它根本不会滚动屏幕。这是我对正在发生的事情所做的说明:

Demo

所以我的问题是,为什么我不能在内部 RelativeLayout 上滚动?我应该以不同的方式组织我的布局吗?

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">

<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="250dp">

// some imageviews and textviews

</RelativeLayout>

<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/header" />

</RelativeLayout>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin" />

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_drawer"
app:menu="@menu/menu_navigation_drawer" />

</android.support.v4.widget.DrawerLayout>

我该如何解决这个问题?

最佳答案

RelativeLayout 如果不在任何可 ScrollView 中则不可滚动。
尝试将您的RelativeLayout 作为您的RecyclerView 的 header 。

在此示例中,您将能够滚动其内容

<ScrollView 
...
...>
<!-- Scrollable Contents -->
</ScrollView>

在你的情况下,我认为最好的方法是让你的 RecyclerView 占据整个屏幕,然后分配它的标题。关注这个linkthis .那里有很多所以只需谷歌一下

关于android - CoordinatorLayout 中的 RelativeLayout 不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41665298/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com