[英]Hide and Show toolbar on scrolling of screen
我在linearlayout
有一个选项卡。 Linearlayout
位于屏幕底部和toolbar
。 我希望当屏幕上的项目超出容纳的数量并且屏幕scrolls
,较低的选项卡linearlayout
应该隐藏,当我scroll
时,它应该可见。 我正在尝试下面的代码,但是它似乎没有用。
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:layout_gravity="bottom"
android:background="@android:color/transparent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible"
app:layout_behavior="com.imi.utils.ScrollingToolbarBehavior"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<include
android:id="@+id/bottomBarLayout"
layout="@layout/activity_custom_bottom_navigation" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
尝试使用
<android.support.design.widget.CoordinatorLayout
...
>
<android.support.design.widget.AppBarLayout
...
>
<android.support.v7.widget.Toolbar
...
/>
</android.support.design.widget.AppBarLayout>
<YourCustomtLinearLayout
...
app:layout_behavior="com.imi.utils.ScrollingToolbarBehavior"
/>
</android.support.design.widget.CoordinatorLayout>
您必须使用setOnScrollChangeListener方法来隐藏和显示工具栏。 最初,您必须为工具栏视图设置可见性。 接下来使用这种方法
appBarLayout.setVisibility(View.GONE);
scroller.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY > oldScrollY) {
appBarLayout.setVisibility(View.VISIBLE);
}
if (scrollY == 0) {
appBarLayout.setVisibility(View.GONE);
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.