[英]Can't scroll RecyclerView, when try to hide toolbar on scrolling
我尝试在本教程中隐藏滚动列表上的工具栏
它适用于我的一个项目,但是当我在另一个项目中尝试时,RecycleView根本不滚动
而不是 RecycleView工具栏是可滚动的!
我的意思是我可以通过滚动工具栏来隐藏工具栏(向下和向上滑动工具栏)
app_bar_main.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="bearing.chavosh.com.bearingdemo.Activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/app_bar_background"
android:theme="@style/AppTheme.AppBarOverlay"
android:background="#f5f5f5">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
android:theme="@style/AppTheme.AppBarOverlay"
app:theme="@style/ThemeOverlay.AppCompat.Light"
app:popupTheme="@style/AppThemePopupOverlayLight">
<bearing.chavosh.com.bearingdemo.Utility.MyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ارسال موقعیت"
android:textSize="17sp"
android:textColor="#000000"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
<View
android:layout_width="match_parent"
android:layout_height="0.25dp"
android:id="@+id/viewShadow"
android:background="#BBBBBB"/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#f5f5f5"
tools:context="bearing.chavosh.com.bearingdemo.Activity.MainActivity"
tools:showIn="@layout/app_bar_main">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/llBarsList">
<include layout="@layout/loads_list"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
load_list.xml 包含在上述源代码中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#f5f5f5"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:showIn="@layout/content_main">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f5f5f5"
app:tabIndicatorColor="#0067A5"
app:tabIndicatorHeight="2dp"
app:tabMode="scrollable"
app:tabGravity="center"/>
<View
android:layout_width="match_parent"
android:layout_height="0.25dp"
android:layout_below="@+id/tabs"
android:id="@+id/viewShadow"
android:background="#BBBBBB"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/viewShadow"
android:id="@+id/vp_bars_list" />
</RelativeLayout>
我没有找到任何答案,我正在研究一天
任何帮助,请
它无法正常工作,因为您通过包含布局将事情搞砸了。 您已包括load_list
XML在content_main
XML,但loads_list
XML包含TabLayout
一些View
和ViewPager
和所有的,你把里面的AppBarLayout
通过<include layout="@layout/loads_list"/>
AppBarLayout
可以包含TabLayout
但ViewPager
会把事情搞砸。 然后在app_main
里面你有另一个AppBarLayout
。 所以把TabLayout
直接进入app_main
下面的XML Toolbar
。 并将ViewPager
包含在它们下方的CoordinatorLayout
。 您可以摆脱那些不必要的 xml 之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.