Code example for Rect

Methods: centerXcenterYoffset

0
     */ 
    private Rect getTargetInWindow() {
        final Rect windowScreen = new Rect();
        getWindowVisibleDisplayFrame(windowScreen);
 
        final Rect target = new Rect(mTargetScreen);
        target.offset(-windowScreen.left, -windowScreen.top);
        return target;
    } 
 
    @Override 
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
 
        final View child = mChild;
        final Rect target = getTargetInWindow();
 
        final int childWidth = child.getMeasuredWidth();
        final int childHeight = child.getMeasuredHeight();
 
        if (mFixedTopPosition != -1) {
            // Horizontally centered, vertically fixed position 
            final int childLeft = (getWidth() - childWidth) / 2;
            final int childTop = mFixedTopPosition;
            layoutChild(child, childLeft, childTop);
        } else { 
            // default is centered horizontally around target... 
            final int childLeft = target.centerX() - (childWidth / 2);
            // ... and vertically aligned a bit below centered 
            final int childTop = target.centerY() - Math.round(childHeight * 0.35f);
 
            // when child is outside bounds, nudge back inside 
            final int clampedChildLeft = clampDimension(childLeft, childWidth, getWidth());
            final int clampedChildTop = clampDimension(childTop, childHeight, getHeight());