Tag: android appbarlayout

CoordinatorLayout + AppBarLayout + NavigationDrawer

将CoordinatorLayout与AppBarLayout和NavigationDrawer结合使用时,我遇到了布局问题。 问题是,NavigationDrawer及其内容隐藏在工具栏后面。 我已经做了大量的研究,并尝试了很多重组,但是没有一个“解决scheme”解决了我的问题。 演示可以在这个小小的Webmvideo中find: https ://goo.gl/yWj3VM 基本风格是Theme.AppCompat.Light.NoActionBar 。 我的activity_overview.xml如下所示: <?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" android:id="@+id/overview_coordinator_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimaryDark" app:layout_scrollFlags="enterAlways|scroll" /> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:clickable="true" android:focusableInTouchMode="true"> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/lorem_ipsum_long" /> </android.support.v4.widget.NestedScrollView> <android.support.design.widget.NavigationView android:id="@+id/nvView" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:background="@android:color/white" app:headerLayout="@layout/nav_header" app:menu="@menu/navigationdrawer_main" /> […]

尽pipeRecyclerView没有足够的内容滚动,但AppBarLayout中的工具栏是可滚动的

是否真的打算在AppBarLayout的工具栏可滚动,虽然“appbar_scrolling_view_behavior”主容器没有足够的内容真正滚动? 到目前为止我所testing的是: 当我使用一个NestedScrollView(“wrap_content”属性)作为主容器和一个TextView作为子,AppBarLayout工作正常,不滚动。 但是,当我使用RecyclerView只有几个条目和“wrap_content”属性(以便不需要滚动)时,即使RecyclerView从未收到滚动事件(使用OnScrollChangeListenertesting),AppBarLayout中的工具栏也是可滚动的)。 这是我的布局代码: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/coordinatorLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content"> <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:theme="@style/ToolbarStyle" /> </android.support.design.widget.AppBarLayout> <android.support.v7.widget.RecyclerView android:id="@+id/recycler" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.CoordinatorLayout> 有以下效果,工具栏是可滚动的,虽然它不是必需的: 我还find了一个方法来处理这个问题,通过检查所有的RecyclerView项是否可见并使用RecyclerView的setNestedScrollingEnabled()方法。 尽pipe如此,它看起来更像是一个打算给我的bug。 有什么意见? :d 编辑#1: 对于可能对我当前的解决scheme感兴趣的人,由于LayoutManager在调用方法来查找时始终返回-1,所以必须将setNestedScrollingEnabled()逻辑置于Handler的postDelayed()方法中,延迟时间为5 ms是否第一个和最后一个项目是可见的。 我在onStart()方法中使用这段代码(在我的RecyclerView被初始化之后),每次发生RecyclerView的内容更改之后。 final LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager(); new Handler().postDelayed(new Runnable() { @Override public void run() { […]