Android: Programmatically Collapse and expand the CollapsingToolbarLayout

mAppBarLayout.setExpanded(true) to expand Toolbar and use mAppBarLayout.setExpanded(false) to collapse Toolbar.

Collapse: Use when Tabs(2,3,4) clicked

CoordinatorLayout.LayoutParams params =(CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
params.height = 3*80; // COLLAPSED_HEIGHT
mAppBarLayout.setLayoutParams(params);
mAppBarLayout.setExpanded(false);


Expand: Use when Tab 1 clicked


CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
params.height = 3*200; // EXPANDED_HEIGHT
mAppBarLayout.setLayoutParams(params);
mAppBarLayout.setExpanded(true);

Contributer

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments:

Popular Posts