Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically remove a layout behavior of my NestedScrollView?

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>
like image 539
Earwin delos Santos Avatar asked Sep 22 '15 10:09

Earwin delos Santos


People also ask

What is coordinator layout in Android?

CoordinatorLayout is a super-powered FrameLayout . CoordinatorLayout is intended for two primary use cases: As a top-level application decor or chrome layout. As a container for a specific interaction with one or more child views.

How do you set layout behavior programmatically?

You can set the behavior on an instance of CoordinatorLayout. LayoutParams with setBehavior method. To get a proper Behavior object that represents the same thing as @string/appbar_scrolling_view_behavior you should create an instance of AppBarLayout. ScrollingViewBehavior .

How to use Nested scroll view in Android?

NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. It is enabled by default. NestedScrollView is used when there is a need for a scrolling view inside another scrolling view.

How do I use CoordinatorLayout?

Layout-Based: Layout-Based behaviors are used to shift one view to some other place when you perform a certain operation. For example, whenever you click on a Floating Action Button(FAB), then that FAB will be moved up and one Snackbar will come from the bottom of the screen.

What is nestedscrollview in Android?

Last Updated : 18 Feb, 2021 NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. It is enabled by default. NestedScrollView is used when there is a need for a scrolling view inside another scrolling view.

How to disable ScrollView programmatically in Android?

This example demonstrates how to do I disable ScrollView programmatically in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Let's try to run your application.

How to add a linearlayout inside a nestedscrollview?

Add the NestedScrollView and inside NestedScrollView add a LinearLayout and inside LinearLayout add two TextView to display the strings which are created inside the strings.xml file and one Button between the TextView. Here is the code for the activity_main.xml file. One can add as many views inside the NestedScrollView’s LinearLayout

How are the nestedscrollviews and extended floating action buttons implemented?

Further, the NestedScrollViews and one Extended Floating Action button are implemented in the layout with gravity “bottom|end”. Inside the NestedScrollView layout sample layout is included for the demonstration purpose.


1 Answers

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);
like image 105
jaxvy Avatar answered Oct 17 '22 22:10

jaxvy