/** * Show this button at the specific location. If this button isn't attached to any parent view * yet, it will be add to activity's root view. If not, it will just update the location. * * @param parent The parent view. Should be {@link FrameLayout} or {@link RelativeLayout} * @param x The x value of anchor point. * @param y The y value of anchor point. * @param gravity The gravity apply with this button. * @see Gravity */ public void show(ViewGroup parent, int x, int y, int gravity) { if (getParent() == null) { ViewGroup.LayoutParams params = parent.generateLayoutParams(null); params.width = mBackground.getIntrinsicWidth(); params.height = mBackground.getIntrinsicHeight(); updateParams(x, y, gravity, params); parent.addView(this, params); } else updateLocation(x, y, gravity); }
/** * Show this button at the specific location. If this button isn't attached to any parent view * yet, it will be add to activity's root view. If not, it will just update the location. * * @param activity The activity that this button will be attached to. * @param x The x value of anchor point. * @param y The y value of anchor point. * @param gravity The gravity apply with this button. * @see Gravity */ public void show(Activity activity, int x, int y, int gravity) { if (getParent() == null) { FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( mBackground.getIntrinsicWidth(), mBackground.getIntrinsicHeight()); updateParams(x, y, gravity, params); activity.getWindow().addContentView(this, params); } else updateLocation(x, y, gravity); }
/** * Update the location of this button. This method only work if it's already attached to a parent * view. * * @param x The x value of anchor point. * @param y The y value of anchor point. * @param gravity The gravity apply with this button. * @see Gravity */ public void updateLocation(int x, int y, int gravity) { if (getParent() != null) updateParams(x, y, gravity, getLayoutParams()); else Log.v( FloatingActionButton.class.getSimpleName(), "updateLocation() is called without parent"); }