Reputation: 259
I have a tabs inside a Linearlayout
. The Linearlayout
is at the bottom of the screen and inside a Toolbar
. I want that when the screen has more items than it can fit and the screen scrolls,the lower tab linearlayout
should hide and when i scroll complete up, it should be visible. I am trying the below code, but it did not seem to be working.
<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>
Upvotes: 0
Views: 746
Reputation: 825
try to use
<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>
Upvotes: 2
Reputation: 21
You have to use setOnScrollChangeListener method for toolbar hide and show. Intially you have to set visiblity gone for toolbarview. next use this method
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);
}
}
});
Upvotes: 2