AppBarLayout doesn't scroll after update to design library 22.2.1, if RecyclerView is inside LinearLayout
Date : March 29 2020, 07:55 AM
will be helpful for those in need It turns out that this was an issue with v22.2.1; I fixed it by advancing to design library v23.0.0.
|
Prevent RecyclerView from scrolling under AppBarLayout before AppBarLayout is collapsed
Tag : android , By : Sergio Rudenko
Date : March 29 2020, 07:55 AM
This might help you Possible solution (untested). Add an OnOffsetChangedListener to your AppBarLayout, and keep note of the offset value. First, declare this field: private boolean shouldScroll = false;
AppBarLayout appbar = findViewById(...);
appbar.addOnOffsetChangedListener(new OnOffsetChangedListener() {
@Override
void onOffsetChanged(AppBarLayout appbar, int offset) {
// Allow recycler scrolling only if we started collapsing.
this.shouldScroll = offset != 0;
}
});
RecyclerView recycler = findViewById(...);
recycler.addOnScrollListener(new OnScrollListener() {
@Override
void onScrolled(RecyclerView recycler, int dx, int dy) {
// If AppBar is fully expanded, revert the scroll.
if (!shouldScroll) {
recycler.scrollTo(0,0);
}
}
});
|
AppBarLayout + NestedScrollView + RecyclerView won't scroll
Tag : android , By : Angel Paunchev
Date : March 29 2020, 07:55 AM
it helps some times Hello I have an issue with the google support appbarLayout my layout structure is like below : , I Solved My problem by enabling nested Scrolling mAppbarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
//collapsed
shouldScroll = true;
} else {
shouldScroll = false;
}
});
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recycler, int dx, int dy) {
// If AppBar is not collapsed, revert the scroll.
if (!shouldScroll) {
if(recycler.getChildCount() >= 0){
recycler.scrollToPosition(0);
}
}
}
});
<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/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_gradient_blue"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:fillViewport="true"
android:scrollbars="none"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/nested_scrollbar_linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical"
android:paddingEnd="8dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingStart="8dip">
<TextView
android:id="@+id/title_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="13sp"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:clickable="true" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
style="@style/AppTheme.Toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_gradient_blue"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="250dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/AppTheme.Toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
app:contentInsetStart="72dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
|
Toolbar in AppBarLayout is scrollable although RecyclerView has not enough content to scroll
Date : March 29 2020, 07:55 AM
|
AppBarLayout hiding toolbar on scroll behavior, switching fragments
Tag : android , By : Jonathan Bernard
Date : March 29 2020, 07:55 AM
|