Add different anchor gravity for small FABs fixes gravity issue

This commit is contained in:
neslihanturan 2018-03-20 15:09:49 +03:00
parent 2afc14eb20
commit ac50886ae0

View file

@ -546,19 +546,20 @@ public class NearbyMapFragment extends DaggerFragment {
private void showFAB() {
addAnchorToFABs(fabPlus, getActivity().findViewById(R.id.bottom_sheet_details).getId());
addAnchorToBigFABs(fabPlus, getActivity().findViewById(R.id.bottom_sheet_details).getId());
fabPlus.show();
addAnchorToFABs(fabGallery, getActivity().findViewById(R.id.empty_view).getId());
addAnchorToSmallFABs(fabGallery, getActivity().findViewById(R.id.empty_view).getId());
addAnchorToFABs(fabCamera, getActivity().findViewById(R.id.empty_view1).getId());
addAnchorToSmallFABs(fabCamera, getActivity().findViewById(R.id.empty_view1).getId());
}
/*
* Add amnchors back before making them visible again.
* */
private void addAnchorToFABs(FloatingActionButton floatingActionButton, int anchorID) {
private void addAnchorToBigFABs(FloatingActionButton floatingActionButton, int anchorID) {
CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams
(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
params.setAnchorId(anchorID);
@ -566,6 +567,18 @@ public class NearbyMapFragment extends DaggerFragment {
floatingActionButton.setLayoutParams(params);
}
/*
* Add amnchors back before making them visible again. Big and small fabs have different anchor
* gravities, therefore the are two methods.
* */
private void addAnchorToSmallFABs(FloatingActionButton floatingActionButton, int anchorID) {
CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams
(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
params.setAnchorId(anchorID);
params.anchorGravity = Gravity.CENTER_HORIZONTAL;
floatingActionButton.setLayoutParams(params);
}
private void passInfoToSheet(Place place) {
this.place = place;
wikipediaButton.setEnabled(place.hasWikipediaLink());