AppBarLayout change offset programmatically

后端 未结 1 778
面向向阳花
面向向阳花 2021-01-12 08:04

How can I change the offset of the AppBarLayout programmatically?

I want a certain offset to the AppBarLayout(partially expanded) when the Activity first loads, then

相关标签:
1条回答
  • 2021-01-12 08:20

    Use this: ScrollableAppBar

    You just have to replace your AppBarLayout with:

    <it.michelelacorte.scrollableappbar.ScrollableAppBar
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="380dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">
    </it.michelelacorte.scrollableappbar.ScrollableAppBar>
    

    and than:

    ScrollableAppBar appBarLayout = (ScrollableAppBar) findViewById(R.id.appbar);
    
    //To give the effect "in the middle" of the image (like gif)
    appBarLayout.collapseToolbar();
    

    Output:

    0 讨论(0)
提交回复
热议问题