How to programatically remove a layout behavior of my NestedScrollView?
Asked Answered
E

1

7

I already achieved the removal of layout_scrollFlags in myCollapsingToolbarLayout. but I need to remove the the layout_behavior of my NestedScrollView so that when there is no contents on my the nested scroll view, the collapsing of the toolbar will be disabled too. Removing the layout_behavior of my NestedScrollView is very easy, just I remove the line of code in your xml literally but how can I remove it programatically?

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>
Enarthrosis answered 22/9, 2015 at 10:25 Comment(4)
You can use Layout Visibility GONE.Cheongsam
I sorry but the collpasing toolbar has a child. so if I am going to set its visibility to gone, the view inside the collpasing toolbar will be gone tooEnarthrosis
@Cheongsam kindly view my updated questionEnarthrosis
@Cheongsam kindly view my updated question, I got the wrong question earlierEnarthrosis
M
13

Try removing the "appbar_scrolling_view_behavior" from the fragment and clearing the scroll flags from the CollapsingToolbarLayout

CoordinatorLayout.LayoutParams coordinatorLayoutParams = (CoordinatorLayout.LayoutParams) pawfileTimeline.getLayoutParams();
coordinatorLayoutParams.setBehavior(null);

AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
toolbarLayoutParams.setScrollFlags(0);
Melisandra answered 3/2, 2016 at 11:54 Comment(1)
Setting the scroll flags to 0 was what worked for me. Removing the CoordinatorLayout behavior would make my toolbar disappear.Caylor

© 2022 - 2024 — McMap. All rights reserved.