Example usage for android.view Gravity CENTER_VERTICAL

List of usage examples for android.view Gravity CENTER_VERTICAL

Introduction

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

Prototype

int CENTER_VERTICAL

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

Click Source Link

Document

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

Usage

From source file:org.ednovo.goorusearchwidget.SearchResults_resource.java

public LinearLayout createResourceEmptyView() {

    LinearLayout scrollChild = new LinearLayout(this);
    scrollChild.setPadding(10, 0, 10, 0);
    resourcelayout = LayoutInflater.from(this).inflate(R.layout.resource_view, null);
    TextView title = (TextView) resourcelayout.findViewById(R.id.textViewTitle);
    title.setText("Sorry! No Results Found");
    title.setTextColor(getResources().getColor(R.color.Grey));
    title.setPadding(50, 50, 0, 10);/*w  ww. j  a  v a  2s. c  o m*/
    title.setTextSize(25);

    scrollChild.addView(resourcelayout, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));
    scrollChild.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    return scrollChild;
}

From source file:com.android.contacts.list.ContactListItemView.java

/**
 * Returns the text view for the contact name, creating it if necessary.
 *//*from   ww  w .ja  va 2s  . c om*/
public TextView getNameTextView() {
    if (mNameTextView == null) {
        mNameTextView = new TextView(getContext());
        mNameTextView.setSingleLine(true);
        mNameTextView.setEllipsize(getTextEllipsis());
        mNameTextView.setTextColor(ResourcesCompat.getColorStateList(getResources(),
                R.color.contact_list_name_text_color, getContext().getTheme()));
        mNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNameTextViewTextSize);
        // Manually call setActivated() since this view may be added after the first
        // setActivated() call toward this whole item view.
        mNameTextView.setActivated(isActivated());
        mNameTextView.setGravity(Gravity.CENTER_VERTICAL);
        mNameTextView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
        mNameTextView.setId(R.id.cliv_name_textview);
        if (CompatUtils.isLollipopCompatible()) {
            mNameTextView.setElegantTextHeight(false);
        }
        addView(mNameTextView);
    }
    return mNameTextView;
}

From source file:org.mobicents.restcomm.android.client.sdk.RCConnection.java

private void logAndToast(String msg) {
    RCLogger.d(TAG, msg);/*from  w  w  w. j  a v a2 s.  co m*/
    if (DO_TOAST) {
        if (logToast != null) {
            logToast.cancel();
        }
        logToast = Toast.makeText(RCClient.getContext(), msg, Toast.LENGTH_SHORT);
        logToast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
        logToast.show();
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

private void addButton(final String senderName, String myEmail, boolean somebodyAnswered, boolean canEdit,
        TableLayout tableLayout, final ButtonTO button) {
    TableRow row = new TableRow(this);
    tableLayout.addView(row);/*from www  .  j ava2  s  . co m*/
    row.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
            TableLayout.LayoutParams.WRAP_CONTENT, 1));

    // XXX: inconsistent margin between 2 rows

    final Button buttonView = new Button(this);
    buttonView.setMinWidth(UIUtils.convertDipToPixels(this, 100));
    buttonView.setText(button.caption);
    buttonView.setTextColor(getResources().getColor(android.R.color.primary_text_dark));
    if (somebodyAnswered)
        buttonView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
    else {
        buttonView.setWidth(mDisplayWidth - UIUtils.convertDipToPixels(this, 12));
    }
    buttonView.setTextSize(19);
    row.addView(buttonView);

    final LinearLayout container = (LinearLayout) getLayoutInflater().inflate(R.layout.message_button_detail,
            null);
    container.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);

    boolean buttonSelectedByMe = false;
    for (MemberStatusTO status : mCurrentMessage.members) {
        if ((status.status & MessagingPlugin.STATUS_ACKED) == MessagingPlugin.STATUS_ACKED
                && ((button.id == null && status.button_id == null)
                        || (button.id != null && button.id.equals(status.button_id)))) {

            getLayoutInflater().inflate(R.layout.avatar, container);
            ImageView avatar = (ImageView) container.getChildAt(container.getChildCount() - 1);

            setAvatar(avatar, status.member);
            if (status.member.equals(myEmail))
                buttonSelectedByMe = true;

            int dp42 = UIUtils.convertDipToPixels(this, 42);
            int dp2 = UIUtils.convertDipToPixels(this, 1);
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) avatar.getLayoutParams();
            lp.setMargins(0, dp2, 0, 0);
            lp.width = dp42;
            lp.height = dp42;
        }
    }

    row.addView(container);

    boolean hasAction = button.action != null && !"".equals(button.action);
    final boolean buttonIsEnabled = canEdit
            && (mCurrentMessage.form != null || !buttonSelectedByMe || hasAction);
    buttonView.setEnabled(buttonIsEnabled);

    int color;
    if (button.id == null || mCurrentMessage.form != null && Message.POSITIVE.equals(button.id)) {
        color = buttonIsEnabled ? Message.GREEN_BUTTON_COLOR : Message.GREENGRAY_BUTTON_COLOR;
    } else if (mCurrentMessage.form != null && Message.NEGATIVE.equals(button.id)) {
        color = buttonIsEnabled ? Message.RED_BUTTON_COLOR : Message.REDGRAY_BUTTON_COLOR;
    } else {
        color = buttonIsEnabled ? Message.BLUE_BUTTON_COLOR : Message.BLUEGRAY_BUTTON_COLOR;
    }
    buttonView.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY);

    buttonView.setOnClickListener(new SafeViewOnClickListener() {

        @Override
        public void safeOnClick(View v) {
            T.UI();
            executeButtonClick(button, container, true);
        }
    });

    final HorizontalScrollView scroller = (HorizontalScrollView) findViewById(R.id.button_scroller);
    scroller.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            scroller.fullScroll(ScrollView.FOCUS_RIGHT);
        }
    });
}

From source file:administrator.example.com.myscrollview.VerticalViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;//from   w  w  w  .ja  v  a2  s .  com
    populate();
    mInLayout = false;

    final int count = getChildCount();
    int width = r - l;
    int height = b - t;
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    final int scrollY = getScrollY();

    int decorCount = 0;

    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            ItemInfo ii;
            int childLeft = 0;
            int childTop = 0;
            if (lp.isDecor) {
                //XXX isDecorfalse
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getMeasuredWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                } /* end of switch */
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getMeasuredHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                } /* end of switch */

                //XXX y?
                childTop += scrollY;
                decorCount++;
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            } else if ((ii = infoForChild(child)) != null) {
                //XXX ViewPager??
                int toff = (height + mPageMargin) * ii.position;
                childLeft = paddingLeft;
                childTop = paddingTop + toff;

                if (DEBUG)
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            } /* end of if */
        } /* end of if */
    } /* end of for */

    //XXX ?
    mLeftPageBounds = paddingLeft;
    mRightPageBounds = width - paddingRight;
    mDecorChildCount = decorCount;
    mFirstLayout = false;
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

private TextView makeCommonTextView(boolean header) {
    TextView textView = new TextView(context, null,
            C.API_LOLLIPOP ? android.R.attr.textAppearanceListItem : android.R.attr.textAppearance);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, C.API_LOLLIPOP ? 14f : 16f);
    textView.setGravity(Gravity.CENTER_VERTICAL);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setSingleLine(true);/*www  . j a  va 2  s  .c o m*/
    if (C.API_LOLLIPOP) {
        textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
        int color = textView.getTextColors().getDefaultColor();
        if (header) {
            color &= 0x5effffff;
        } else {
            color &= 0xddffffff;
        }
        textView.setTextColor(color);
    }
    return textView;
}

From source file:com.bluetoothlamp.tiny.view.verticalview.VerticalViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;//from   w ww. j  a v a  2  s. co  m
    populate();
    mInLayout = false;

    final int count = getChildCount();
    int width = r - l;
    int height = b - t;
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    final int scrollY = getScrollY();

    int decorCount = 0;

    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            ItemInfo ii;
            int childLeft = 0;
            int childTop = 0;
            if (lp.isDecor) {
                //XXX isDecor??alse??
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getMeasuredWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                } /* end of switch */
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getMeasuredHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                } /* end of switch */

                //XXX y??
                childTop += scrollY;
                decorCount++;
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            } else if ((ii = infoForChild(child)) != null) {
                //XXX ViewPager
                int toff = (height + mPageMargin) * ii.position;
                childLeft = paddingLeft;
                childTop = paddingTop + toff;

                if (DEBUG)
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            } /* end of if */
        } /* end of if */
    } /* end of for */

    //XXX 
    mLeftPageBounds = paddingLeft;
    mRightPageBounds = width - paddingRight;
    mDecorChildCount = decorCount;
    mFirstLayout = false;
}

From source file:com.ynchinamobile.install.VerticalViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/* w  w w. ja  v a 2 s  .  co m*/
    populate();
    mInLayout = false;

    final int count = getChildCount();
    int width = r - l;
    int height = b - t;
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    final int scrollY = getScrollY();

    int decorCount = 0;

    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            ItemInfo ii;
            int childLeft = 0;
            int childTop = 0;
            if (lp.isDecor) {
                //XXX isDecor??alse??
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getMeasuredWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                } /* end of switch */
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getMeasuredHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                } /* end of switch */

                //XXX ???
                childTop += scrollY;
                decorCount++;
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            } else if ((ii = infoForChild(child)) != null) {
                //XXX ViewPager
                int toff = (height + mPageMargin) * ii.position;
                childLeft = paddingLeft;
                childTop = paddingTop + toff;

                if (DEBUG)
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            } /* end of if */
        } /* end of if */
    } /* end of for */

    //XXX 
    mLeftPageBounds = paddingLeft;
    mRightPageBounds = width - paddingRight;
    mDecorChildCount = decorCount;
    mFirstLayout = false;
}

From source file:com.emoiluj.doubleviewpager.HorizontalViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*  w ww. jav a 2 s.c  om*/
    populate();
    mInLayout = false;

    final int count = getChildCount();
    int width = r - l;
    int height = b - t;
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    final int scrollX = getScrollX();

    int decorCount = 0;

    // First pass - decor views. We need to do this in two passes so that
    // we have the proper offsets for non-decor views later.
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int childLeft = 0;
            int childTop = 0;
            if (lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getMeasuredWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                }
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getMeasuredHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                }
                childLeft += scrollX;
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
                decorCount++;
            }
        }
    }

    // Page views. Do this once we have the right padding offsets from above.
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            ItemInfo ii;
            if (!lp.isDecor && (ii = infoForChild(child)) != null) {
                int loff = (int) (width * ii.offset);
                int childLeft = paddingLeft + loff;
                int childTop = paddingTop;
                if (lp.needsMeasure) {
                    // This was added during layout and needs measurement.
                    // Do it now that we know what we're working with.
                    lp.needsMeasure = false;
                    final int widthSpec = MeasureSpec.makeMeasureSpec(
                            (int) ((width - paddingLeft - paddingRight) * lp.widthFactor), MeasureSpec.EXACTLY);
                    final int heightSpec = MeasureSpec
                            .makeMeasureSpec((int) (height - paddingTop - paddingBottom), MeasureSpec.EXACTLY);
                    child.measure(widthSpec, heightSpec);
                }
                if (DEBUG) {
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                }
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            }
        }
    }
    mTopPageBounds = paddingTop;
    mBottomPageBounds = height - paddingBottom;
    mDecorChildCount = decorCount;
    mFirstLayout = false;
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

private View makeView(boolean icon, boolean watcher, boolean closeable, float density) {
    int size = (int) (48f * density);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setGravity(Gravity.CENTER_VERTICAL);
    ImageView iconView = null;//w ww  .  j  a v a 2s .c  om
    if (icon) {
        iconView = new ImageView(context);
        iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        linearLayout.addView(iconView, (int) (24f * density), size);
    }
    TextView textView = makeCommonTextView(false);
    linearLayout.addView(textView, new LinearLayout.LayoutParams(0, size, 1));
    WatcherView watcherView = null;
    if (watcher) {
        watcherView = new WatcherView(context);
        linearLayout.addView(watcherView, size, size);
    }
    ImageView closeView = null;
    if (!watcher && closeable) {
        closeView = new ImageView(context);
        closeView.setScaleType(ImageView.ScaleType.CENTER);
        closeView.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonCancel, 0));
        closeView.setBackgroundResource(ResourceUtils.getResourceId(context,
                android.R.attr.borderlessButtonStyle, android.R.attr.background, 0));
        linearLayout.addView(closeView, size, size);
        closeView.setOnClickListener(closeButtonListener);
    }
    ViewHolder holder = new ViewHolder();
    holder.icon = iconView;
    holder.text = textView;
    holder.extra = watcherView != null ? watcherView : closeView;
    linearLayout.setTag(holder);
    int layoutLeftDp = 0;
    int layoutRightDp = 0;
    int textLeftDp;
    int textRightDp;
    if (C.API_LOLLIPOP) {
        textLeftDp = 16;
        textRightDp = 16;
        if (icon) {
            layoutLeftDp = 16;
            textLeftDp = 32;
        }
        if (watcher || closeable) {
            layoutRightDp = 4;
            textRightDp = 8;
        }
    } else {
        textLeftDp = 8;
        textRightDp = 8;
        if (icon) {
            layoutLeftDp = 8;
            textLeftDp = 6;
            textView.setAllCaps(true);
        }
        if (watcher || closeable) {
            layoutRightDp = 0;
            textRightDp = 0;
        }
    }
    linearLayout.setPadding((int) (layoutLeftDp * density), 0, (int) (layoutRightDp * density), 0);
    textView.setPadding((int) (textLeftDp * density), 0, (int) (textRightDp * density), 0);
    return linearLayout;
}