- int top = fab.getTop();
- ViewParent parent = fab.getParent();
- while (parent != null && !(parent instanceof View))
- parent = parent.getParent();
-
- if (parent != null) {
- View parentView = (View) parent;
- int parentHeight = parentView.getHeight();
- fabVerticalOffset = parentHeight - top;
- }
+ fab.measure(0, 0);
+
+ int height = fab.getMeasuredHeight();
+
+ int bottomMargin;
+
+ ViewGroup.LayoutParams layoutParams = fab.getLayoutParams();
+ if (layoutParams instanceof ViewGroup.MarginLayoutParams)
+ bottomMargin = ((ViewGroup.MarginLayoutParams) layoutParams).bottomMargin;
+ else
+ throw new RuntimeException("Unsupported layout params " + layoutParams.getClass()
+ .getCanonicalName());
+
+ fabVerticalOffset = height + bottomMargin;