Answer the question
In order to leave comments, you need to log in
How to move FloatingActionButton down?
I have a ScrollingActivity.FAB attached to an AppBarLayout.
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_check_white_48dp"
app:layout_anchor="@id/carSelectAppBar"
app:layout_anchorGravity="bottom|end"
/>
mToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.carSelectToolbar);
mAppBarLayout = (AppBarLayout) findViewById(R.id.carSelectAppBar);
mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
int scrollRange = -1;
boolean isShow = false;
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (scrollRange == -1) {
scrollRange = appBarLayout.getTotalScrollRange();
}
if (scrollRange + verticalOffset == 0) {
isShow = true;
changeFloatButtonState(isShow,fab);
} else if (isShow) {
isShow = false;
changeFloatButtonState(isShow,fab);
}
}
});
private void changeFloatButtonState(boolean isShow,FloatingActionButton fab) {
if (!isShow) {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
params.setAnchorId(R.id.carSelectAppBar);
params.anchorGravity = Gravity.BOTTOM | Gravity.END;
fab.setLayoutParams(params);
} else {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
params.setAnchorId(R.id.carSelectContentLayout);
params.anchorGravity = Gravity.BOTTOM | Gravity.END;
fab.setLayoutParams(params);
}
}
An anchor may not be changed after CoordinatorLayout measurement begins before layout is complete.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question