Change layout_scrollFlags programmatically in CollapsingToolbarLayout

旧街凉风 提交于 2019-12-22 03:17:12

问题


I have the following CollapsingToolbarLayout tag in my xml:

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsingToolbarLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:contentScrim="?attr/colorPrimary"
    app:expandedTitleMarginStart="@dimen/expanded_toolbar_title_margin_start"
    app:layout_scrollFlags="exitUntilCollapsed">

I would like to change the scrollFlags value programmatically (run time) - specifically, toggle the scrollable flag. Is it possible?


回答1:


CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) collapsingToolbar.getLayoutParams();
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP); // list other flags here by |
collapsingToolbar.setLayoutParams(params);

One thing worth mentioning - setScrollFlags overrides all previous flags so we should be careful not to lose already existing flag



来源:https://stackoverflow.com/questions/32407936/change-layout-scrollflags-programmatically-in-collapsingtoolbarlayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!