How to programmatically remove the layout behavior of my NestedScrollView?

I have already achieved layout_scrollFlags removal in my CollapsingToolbarLayout . but I need to remove the layout_behavior my NestedScrollView , so that when there is no content in my scroll view, the toolbar will also fail. Removing the layout_behavior of my NestedScrollView is very simple, I just delete the line of code in your xml literally, but how can it be removed programmatically?

my xml:

 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:background="@android:color/white"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <fragment android:id="@+id/pawfile_header" android:name="com.lightbulb.pawesome.fragments.PawfileHeaderFragment" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:fitsSystemWindows="true" app:layout_collapseMode="parallax" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <fragment android:id="@+id/pawfile_timeline" android:name="com.lightbulb.pawesome.user_timeline.PawesomeUserTimelineFragment" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.CoordinatorLayout> 
+6
source share
2 answers

Try removing "appbar_scrolling_view_behavior" from the snippet and clear the scroll flags from CollapsingToolbarLayout

 CoordinatorLayout.LayoutParams coordinatorLayoutParams = (CoordinatorLayout.LayoutParams) pawfileTimeline.getLayoutParams(); coordinatorLayoutParams.setBehavior(null); AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); toolbarLayoutParams.setScrollFlags(0); 
+10
source

You can programmatically remove the layout behavior of your NestedScrollView by setting it to null in its LayoutParams, which should be of type CoordinatorLayout.LayoutParams:

 CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) myNestedScrollView.getLayoutParams(); params.setBehavior( null ); 
+1
source

All Articles