How can I programmatically change the AppBarLayout offset?
I want some bias towards AppBarLayout (partially extended), when Activity is loaded first, then the user can expand it or collapse it. The current behavior is that it expands completely when Activity is loaded first.
my.xml
<android.support.design.widget.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="300dp" android:fitsSystemWindows="true" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" android:clickable="true" android:fitsSystemWindows="true" app:expandedTitleMarginEnd="64dp" app:expandedTitleMarginStart="48dp" app:layout_collapseParallaxMultiplier="0.7" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" app:layout_collapseMode="parallax"> <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:src="@drawable/pic"/> <View android:id="@+id/overlay" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/overlay" app:layout_collapseMode="pin"/> </FrameLayout> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:title="@string/app_name"/> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout>
Must support API 16+
Thanks!
source share