Android RecyclerView不会与抽屉布局和底部板材一起滚动内部坐标布局
我有一个布局包含导航抽屉,工具栏和底页。RecyclerView也出现在不滚动的布局中 根布局是CoordinatorLayout,它封装了->i)抽屉布局和ii)嵌套滚动视图(用于底部工作表行为) 抽屉布局封装->i)线性布局和ii)导航视图 线性布局封装->i)工具栏ii)约束布局 ConstraintLayout封装->i)ViewPager ii)TextView iii)RecyclerView(这不会滚动 下面是我的xml:Android RecyclerView不会与抽屉布局和底部板材一起滚动内部坐标布局,android,android-recyclerview,android-coordinatorlayout,drawerlayout,android-nestedscrollview,Android,Android Recyclerview,Android Coordinatorlayout,Drawerlayout,Android Nestedscrollview,我有一个布局包含导航抽屉,工具栏和底页。RecyclerView也出现在不滚动的布局中 根布局是CoordinatorLayout,它封装了->i)抽屉布局和ii)嵌套滚动视图(用于底部工作表行为) 抽屉布局封装->i)线性布局和ii)导航视图 线性布局封装->i)工具栏ii)约束布局 ConstraintLayout封装->i)ViewPager ii)TextView iii)RecyclerView(这不会滚动 下面是我的xml: <?xml version="1.0&qu
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="e.a.exlorista_customer.MainActivity">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorActionBarBackground"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/imgSliderVP"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/nearByStoresTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Nearby Stores"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="@+id/imgSliderVP"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"/>
<android.support.v7.widget.RecyclerView
<!-- This does not scroll -->
android:id="@+id/storeRV"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toBottomOf="@+id/nearByStoresTV" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_menu" />
</android.support.v4.widget.DrawerLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/cartSummary_MainActivityNSV"
android:layout_width="match_parent"
android:layout_height="65sp"
android:clipToPadding="true"
android:background="@color/colorActionBarBackground"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:id="@+id/cartSummary_MainActivityLL"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp">
<TextView
android:id="@+id/cartItemCount_MainActivityTV"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="0.4"
android:textColor="@color/colorActionBarTitleText"
android:textStyle="bold"
android:textSize="20sp"
android:gravity="center_vertical"
android:text="1 item"/>
<Button
android:id="@+id/proceedToCart_MainActivityB"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="0.6"
android:text="Proceed to cart"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
ConstraintLayout封装->i)ViewPager ii)TextView iii)
RecyclerView(不滚动)
当然不会
应该是抽屉布局的直接子项。另外,如果您正在使用CoordinatorLayout
和NestedScrollView
,则可能必须在CoordinatorLayout
中添加AppBarLayout
布局示例:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ui.MainActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="0dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:overScrollMode="never"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="false">
<androidx.appcompat.widget.Toolbar
android:id="@+id/myToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<!-- Your nestedScrollview here which should have this attribute
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> -->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_view_header"
app:menu="@menu/main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
命名空间。您现在可以迁移了。感谢您指出CoordinatorLayout应该是DroperLayout的直接子级。也许,这是我需要做的第一件正确的事情。但是,为NestedScrollView设置属性app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”并不是我想要的,因为它应该是底部工作表,所以layout\u behavior属性必须是app:layout\u behavior=“android.support.design.widget.BottomSheetBehavior”。另外,我不必使用AppBarLayout,constraintLayout必须封装在另一个NestedScrollView中。通过将属性app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
设置为NestedScrollView
,我将,我的意思是对您试图在AppBarLayout
下滚动的内容使用此属性。此外,这也是通过使用NestedScrollView
中的app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
实现滚动行为的常用方法,也许您应该从它如何与NestedScrollView
和协调布局
配合工作中汲取一些想法