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:smart.services.adapter.ManageCarsAdapter.java

private void deleteDialog(final int position) {
    final TextView input = new TextView(context);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    alertDialogBuilder.setTitle("Delete");

    alertDialogBuilder.setCancelable(false).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        @SuppressLint("DefaultLocale")
        public void onClick(DialogInterface dialog, int id) {
            DeleteCar deleteCar = new DeleteCar(position);
            deleteCar.execute();// w w  w . j  a  v a2s.c o  m
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    input.setText("Are You sure You want to delete this record ?");
    input.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    input.setTextSize(20);
    input.setLayoutParams(lp);
    alertDialog.setView(input);
    alertDialog.show();
}

From source file:com.nokia.example.capturetheflag.Controller.java

@Override
public void onUpdatePlayerMessage(UpdatePlayerResponse update) {
    if (mCurrentGame == null) {
        return;/*from  w  ww. j  av  a 2 s.com*/
    }

    Player updatedPlayer = update.getUpdatedPlayer();

    if (!mCurrentGame.getPlayers().contains(update.getUpdatedPlayer())) {
        Log.d(TAG, "onUpdatePlayerMessage(): New player");
        mCurrentGame.getPlayers().add(updatedPlayer);

        /* Show a toast message informing the user that a new player has
         * joined the game.
         */
        final String playerName = updatedPlayer.getName();

        mUIHandler.post(new Runnable() {
            @Override
            public void run() {
                String text = getString(R.string.new_player_joined, playerName);
                Toast toast = Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
            }
        });
    } else {
        Log.d(TAG, "onUpdatePlayerMessage(): Existing player");
        int i = mCurrentGame.getPlayers().indexOf(updatedPlayer);
        Player old = mCurrentGame.getPlayers().get(i);
        mMap.updateMarkerForPlayer(updatedPlayer, old);
        mCurrentGame.getPlayers().set(i, updatedPlayer);
    }

    mMap.updatePlayerMarkerPosition(updatedPlayer);
}

From source file:de.vanita5.twittnuker.activity.support.QuickSearchBarActivity.java

private void updateWindowAttributes() {
    final Window window = getWindow();
    final WindowManager.LayoutParams attributes = window.getAttributes();
    attributes.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
    window.setAttributes(attributes);//w  w  w.  ja v a  2  s  .  c o  m
}

From source file:com.iangclifton.android.floatlabel.FloatLabel.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void layoutChild(View child, int parentLeft, int parentTop, int parentRight, int parentBottom) {
    if (child.getVisibility() != GONE) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int width = child.getMeasuredWidth();
        final int height = child.getMeasuredHeight();

        int childLeft;
        final int childTop = parentTop + lp.topMargin;

        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.START;
        }/*from   w  w w . j  a v  a  2  s  .  c om*/

        final int layoutDirection;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            layoutDirection = LAYOUT_DIRECTION_LTR;
        } else {
            layoutDirection = getLayoutDirection();
        }

        final int absoluteGravity = GravityCompat.getAbsoluteGravity(gravity, layoutDirection);

        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin;
            break;
        case Gravity.RIGHT:
            childLeft = parentRight - width - lp.rightMargin;
            break;
        case Gravity.LEFT:
        default:
            childLeft = parentLeft + lp.leftMargin;
        }

        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}

From source file:android.support.v7ox.view.menu.ActionMenuItemView.java

@Override
public boolean onLongClick(View v) {
    if (hasText()) {
        // Don't show the cheat sheet for items that already show text.
        return false;
    }//from   w  w w.  ja  va 2s .co m

    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);

    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    int referenceX = screenPos[0] + width / 2;
    if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) {
        final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
        referenceX = screenWidth - referenceX; // mirror
    }
    Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX,
                screenPos[1] + height - displayFrame.top);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    return true;
}

From source file:com.vinfotech.widget.FloatLabel.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void layoutChild(View child, int parentLeft, int parentTop, int parentRight, int parentBottom) {
    if (child.getVisibility() != GONE) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int width = child.getMeasuredWidth();
        final int height = child.getMeasuredHeight();

        int childLeft;
        final int childTop = parentTop + lp.topMargin;

        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.START;
        }/*from w w w  . j ava2 s  .  c  om*/

        final int layoutDirection;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            layoutDirection = LAYOUT_DIRECTION_LTR;
        } else {
            layoutDirection = getLayoutDirection();
        }

        final int absoluteGravity = GravityCompat.getAbsoluteGravity(gravity, layoutDirection);

        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin;
            break;
        case Gravity.RIGHT:
            childLeft = parentRight - width - lp.rightMargin;
            break;
        case Gravity.LEFT:

        default:
            childLeft = parentLeft + lp.leftMargin;
        }

        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}

From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java

private void initAdjustProgressView() {
    mAdjustProgressView = new TextView(mAppContext);
    mAdjustProgressView.setTextSize(20);
    mAdjustProgressView.setTextColor(0xfffafafa);
    mAdjustProgressView.setBackgroundResource(R.drawable.bg_video_progress_adjust);
    LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER_HORIZONTAL;
    lp.topMargin = UnitUtil.dp2px(mAppContext, 100);
    addView(mAdjustProgressView, lp);/*w  w w  .  jav a2  s .  c  o  m*/
    mAdjustProgressView.setVisibility(GONE);
}

From source file:com.chalmers.schmaps.CheckBusActivity.java

/**
 * Makes the rows for the lindholmentable
 *//*w ww  .  j a va 2  s.co m*/
public void makeLindholmenRows() {
    for (int i = 0; i < NROFROWS; i++) {
        TableRow tempTableRow = new TableRow(this);
        tempTableRow.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        // Makes every other row light gray or white
        if (i % 2 == 0) {
            tempTableRow.setBackgroundColor(getResources().getColor(R.color.transp_grey));
        } else {
            tempTableRow.setBackgroundColor(getResources().getColor(R.color.transp_white));
        }

        //Makes every textview for each column and add it before starting with a new one 
        for (int j = 0; j < NR_OF_COLUMNS; j++) {
            TextView textview = new TextView(this);
            textview.setTextColor(Color.BLACK);
            textview.setTextSize(TypedValue.COMPLEX_UNIT_SP, TEXT_SIZE);
            //Check which content should be written in the textview
            if (j == COLUMN_NR_1) {
                textview.setText(lindholmenLineArray.get(i));
            } else if (j == COLUMN_NR_2) {
                textview.setText(lindholmenDestArray.get(i));
            } else if (j == COLUMN_NR_3) {
                textview.setText(lindholmenTimeArray.get(i));
            } else if (j == COLUMN_NR_4) {
                textview.setText(lindholmenTrackArray.get(i));
            }

            textview.setGravity(Gravity.CENTER_HORIZONTAL);
            tempTableRow.addView(textview);
        }
        lindholmenTable.addView(tempTableRow,
                new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    }
}

From source file:android.support.v7.internal.view.menu.ActionMenuItemView.java

@Override
public boolean onLongClick(View v) {
    if (hasText()) {
        // Don't show the cheat sheet for items that already show text.
        return false;
    }// ww  w.j  a v  a  2 s.c o m

    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);

    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    int referenceX = screenPos[0] + width / 2;
    if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) {
        final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
        referenceX = screenWidth - referenceX; // mirror
    }
    Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, height);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    return true;
}

From source file:com.handmark.pulltorefresh.library.PullToRefreshListView.java

@Override
protected void handleStyledAttributes(TypedArray a) {
    super.handleStyledAttributes(a);

    mListViewExtrasEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrListViewExtrasEnabled, true);

    if (mListViewExtrasEnabled) {
        final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL);

        // Create Loading Views ready for use later
        FrameLayout frame = new FrameLayout(getContext());
        mHeaderLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_START, a);
        mHeaderLoadingView.setVisibility(View.GONE);
        frame.addView(mHeaderLoadingView, lp);
        mRefreshableView.addHeaderView(frame, null, false);

        mLvFooterLoadingFrame = new FrameLayout(getContext());
        mFooterLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_END, a);
        mFooterLoadingView.setVisibility(View.GONE);
        mLvFooterLoadingFrame.addView(mFooterLoadingView, lp);

        /**/*  w  ww .  ja v a2 s. com*/
         * If the value for Scrolling While Refreshing hasn't been
         * explicitly set via XML, enable Scrolling While Refreshing.
         */
        if (!a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) {
            setScrollingWhileRefreshingEnabled(true);
        }
    }
}