Example usage for android.view Gravity CENTER_HORIZONTAL

List of usage examples for android.view Gravity CENTER_HORIZONTAL

Introduction

In this page you can find the example usage for android.view Gravity CENTER_HORIZONTAL.

Prototype

int CENTER_HORIZONTAL

To view the source code for android.view Gravity CENTER_HORIZONTAL.

Click Source Link

Document

Place object in the horizontal center of its container, not changing its size.

Usage

From source file:de.vanita5.twittnuker.util.Utils.java

public static void showMenuItemToast(final View v, final CharSequence text, final boolean isBottomBar) {
    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    v.getLocationOnScreen(screenPos);/* ww  w. j a  v  a 2  s .  c o m*/
    v.getWindowVisibleDisplayFrame(displayFrame);
    final int width = v.getWidth();
    final int height = v.getHeight();
    final int screenWidth = v.getResources().getDisplayMetrics().widthPixels;
    final Toast cheatSheet = Toast.makeText(v.getContext(), text, Toast.LENGTH_SHORT);
    if (isBottomBar) {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    } else {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT, screenWidth - screenPos[0] - width / 2, height);
    }
    cheatSheet.show();
}

From source file:com.appunite.list.AbsHorizontalListView.java

private void positionPopup() {
    int screenHeight = getResources().getDisplayMetrics().heightPixels;
    final int[] xy = new int[2];
    getLocationOnScreen(xy);/*  ww w  . j ava  2  s  .co  m*/
    // TODO: The 20 below should come from the theme
    // TODO: And the gravity should be defined in the theme as well
    final int bottomGap = screenHeight - xy[1] - getHeight() + (int) (mDensityScale * 20);
    if (!mPopup.isShowing()) {
        mPopup.showAtLocation(this, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, xy[0], bottomGap);
    } else {
        mPopup.update(xy[0], bottomGap, -1, -1);
    }
}