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:com.mk4droid.IMC_Activities.FActivity_TabHost.java

private LinearLayout ActivateColorize(LinearLayout ll, String text, Drawable dr) {

    // text//  w w w .  j  a  va  2s . c om
    TextView v = (TextView) ll.findViewWithTag("tv");
    v.setText(text);
    v.setTextSize(10);
    v.setTextColor(Color.BLACK); //v.setTextColor(Color.WHITE);
    v.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

    //dr.setColorFilter(0xFF888888, android.graphics.PorterDuff.Mode.MULTIPLY);
    dr.setColorFilter(resources.getColor(R.color.orange), android.graphics.PorterDuff.Mode.SRC_ATOP);

    v.setCompoundDrawablesWithIntrinsicBounds(null, dr, null, null);
    v.setPadding(0, 5, 0, 2);

    v.setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_tabs_focused));

    // hbar
    View hbar = ll.findViewWithTag("hbar");
    //hbar.setBackgroundColor(resources.getColor(R.color.orange));
    hbar.setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_orange));

    return ll;
}

From source file:com.org.ccl.practicetwo.camera.Camera2BasicFragment.java

@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
    mTextureView = view.findViewById(R.id.texture);
    View rightButtonLayout = view.findViewById(R.id.right_button_layout);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) rightButtonLayout.getLayoutParams();
    layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT;
    layoutParams.rightMargin = DensityUtils.dp2px(getActivity(), 5);
    rightButtonLayout.setLayoutParams(layoutParams);
    mTvTakePhoto = rightButtonLayout.findViewById(R.id.tv_take_photo);
    mTvDetermine = rightButtonLayout.findViewById(R.id.tv_determine);
    mTvCancel = rightButtonLayout.findViewById(R.id.tv_cancel);
    mTvTakePhoto.setOnClickListener(this);
    mTvDetermine.setOnClickListener(this);
    mTvCancel.setOnClickListener(this);
}

From source file:com.example.mapsv2.ClustersAreListsActivity.java

private void showInfo(final int x, int y, final Cluster cluster) {
    final int orientation = getResources().getConfiguration().orientation;

    // (re-)Load cluster data into the ListView
    @SuppressWarnings("unchecked")
    ArrayAdapter<String> adapter = (ArrayAdapter<String>) listView.getAdapter();
    adapter.clear();/*from www . j a v a  2s . co  m*/

    for (Marker m : cluster.markers) {
        adapter.add(m.getTitle());
    }
    adapter.notifyDataSetChanged();

    // Reconfigure the layout params to position the info window on screen
    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) infoWindow.getLayoutParams();

    if (orientation == Configuration.ORIENTATION_PORTRAIT) {
        lp.topMargin = y;
        lp.leftMargin = defaultMargin;
        lp.rightMargin = defaultMargin;
        lp.width = LayoutParams.MATCH_PARENT;
        lp.height = LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.LEFT | Gravity.TOP;
        infoWindow.setBackgroundResource(R.drawable.info_window_bg_up);
    } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        lp.leftMargin = x + defaultMargin;
        lp.topMargin = defaultMargin;
        lp.bottomMargin = defaultMargin;
        lp.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
        lp.width = LayoutParams.WRAP_CONTENT;
        lp.height = LayoutParams.WRAP_CONTENT;
        infoWindow.setBackgroundResource(R.drawable.info_window_bg_left);
    }
    infoWindow.setLayoutParams(lp);
    fullScreenOverlay.setVisibility(View.VISIBLE);
}

From source file:com.facebook.react.views.textinput.ReactTextInputManager.java

@ReactProp(name = ViewProps.TEXT_ALIGN_VERTICAL)
public void setTextAlignVertical(ReactEditText view, @Nullable String textAlignVertical) {
    if (textAlignVertical == null || "auto".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.NO_GRAVITY);
    } else if ("top".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.TOP);
    } else if ("bottom".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.BOTTOM);
    } else if ("center".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.CENTER_VERTICAL);
    } else {/*from  w ww.j ava 2 s.  co m*/
        throw new JSApplicationIllegalArgumentException("Invalid textAlignVertical: " + textAlignVertical);
    }
}

From source file:com.itsronald.widget.ViewPagerIndicator.java

/**
 * Calculate the starting vertical position for the line of indicator dots.
 * @return The first Y coordinate where the indicator dots start.
 *///  w  w w .  ja  v  a  2s .  c o m
@Px
private int calculateIndicatorDotTop() {
    final int top;
    final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
    switch (verticalGravity) {
    default:
    case Gravity.CENTER_VERTICAL:
        top = (getHeight() - getPaddingTop() - getPaddingBottom()) / 2 - getDotRadius();
        break;
    case Gravity.TOP:
        top = getPaddingTop();
        break;
    case Gravity.BOTTOM:
        top = getHeight() - getPaddingBottom() - 2 * getDotRadius();
        break;
    }
    return top;
}

From source file:android.support.v7.widget.ToolbarWidgetWrapper.java

private void ensureSpinner() {
    if (mSpinner == null) {
        mSpinner = new AppCompatSpinner(getContext(), null, R.attr.actionDropDownStyle);
        Toolbar.LayoutParams lp = new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL);
        mSpinner.setLayoutParams(lp);//from   w w  w  .  j a  v  a2s . c  o  m
    }
}

From source file:net.grobas.widget.AutoLinearLayout.java

private void updateTopPositionByGravity(ViewPosition pos, int size, int gravity) {
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        pos.top += (size > 0) ? size : 0;
        break;/*from w ww .  j  av a 2s  .  com*/

    case Gravity.CENTER_VERTICAL:
        pos.top += ((size > 0) ? size : 0) / 2;
        break;
    }
}

From source file:com.wit.and.dialog.LoginDialog.java

/**
 * // w ww.j  a v  a 2s. c om
 */
@Override
protected View onCreateBodyView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = inflater.getContext();

    RelativeLayout layout = new RelativeLayout(context);
    // Apply neutral layout params.
    layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    // Do not allow to apply style to body view.
    // layout.setId(R.id.Dialog_Layout_Body);

    // Create layout for loading view.
    LinearLayout loadingLayout = new LinearLayout(context);
    loadingLayout.setOrientation(LinearLayout.HORIZONTAL);
    loadingLayout.setGravity(Gravity.CENTER_VERTICAL);
    // Allow styling of loading layout as body layout.
    loadingLayout.setId(R.id.And_Dialog_Layout_Body);

    // Create text view for message.
    TextView msgTextView = new TextView(context);
    msgTextView.setId(R.id.And_Dialog_TextView_Message);

    // Create circle progress bar.
    ProgressBar circleProgressBar = new ProgressBar(context);
    circleProgressBar.setId(R.id.And_Dialog_ProgressBar);

    // Build loading view.
    loadingLayout.addView(circleProgressBar, new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    loadingLayout.addView(msgTextView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    loadingLayout.setVisibility(View.GONE);

    // Insert loading layout into main body layout.
    RelativeLayout.LayoutParams loadingLayoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    loadingLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    layout.addView(loadingLayout, loadingLayoutParams);

    // Create layout for edit texts.
    LinearLayout editLayout = new LinearLayout(context);
    editLayout.setOrientation(LinearLayout.VERTICAL);
    editLayout.setId(R.id.And_Dialog_Layout_LoginDialog_EditView);

    // Create edit texts for username and password.
    EditText userEdit = new EditText(context);
    userEdit.setId(R.id.And_Dialog_EditText_Username);
    userEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    EditText passEdit = new EditText(context);
    passEdit.setId(R.id.And_Dialog_EditText_Password);
    passEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

    // Create edit texts divider.
    DialogDivider divider = new DialogDivider(context);
    divider.setId(R.id.And_Dialog_Divider_LoginDialog_EditTexts);

    // Build edit layout.
    editLayout.addView(userEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    editLayout.addView(divider, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    editLayout.addView(passEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    // Add custom layout.
    View customView = onCreateCustomView(inflater, editLayout, savedInstanceState);
    if (customView != null) {
        editLayout.addView(this.mCustomView = customView);
    }

    // Insert edit layout into main body layout.
    RelativeLayout.LayoutParams editLayoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    editLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    layout.addView(editLayout, editLayoutParams);

    return layout;
}

From source file:com.mk4droid.IMC_Activities.FActivity_TabHost.java

private LinearLayout InActivateColorize(LinearLayout ll, String text, Drawable dr) {

    // text/*from   ww w . j  a  va2 s. com*/
    TextView v = (TextView) ll.findViewWithTag("tv");

    v.setText(text);
    v.setTextSize(10);
    v.setTextColor(Color.GRAY);
    v.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

    dr.setColorFilter(0xFF888888, android.graphics.PorterDuff.Mode.SRC_ATOP);
    v.setCompoundDrawablesWithIntrinsicBounds(null, dr, null, null);
    v.setPadding(0, 5, 0, 2);

    v.setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_tabs));

    // hbar
    View hbar = ll.findViewWithTag("hbar");
    hbar.setBackgroundDrawable(null);
    hbar.setBackgroundColor(resources.getColor(R.color.graylight));
    return ll;
}

From source file:android.support.v7.widget.LinearLayoutCompat.java

@Override
public int getBaseline() {
    if (mBaselineAlignedChildIndex < 0) {
        return super.getBaseline();
    }/*from ww  w.j  a va 2s .  c  om*/

    if (getChildCount() <= mBaselineAlignedChildIndex) {
        throw new RuntimeException(
                "mBaselineAlignedChildIndex of LinearLayout " + "set to an index that is out of bounds.");
    }

    final View child = getChildAt(mBaselineAlignedChildIndex);
    final int childBaseline = child.getBaseline();

    if (childBaseline == -1) {
        if (mBaselineAlignedChildIndex == 0) {
            // this is just the default case, safe to return -1
            return -1;
        }
        // the user picked an index that points to something that doesn't
        // know how to calculate its baseline.
        throw new RuntimeException("mBaselineAlignedChildIndex of LinearLayout "
                + "points to a View that doesn't know how to get its baseline.");
    }

    // TODO: This should try to take into account the virtual offsets
    // (See getNextLocationOffset and getLocationOffset)
    // We should add to childTop:
    // sum([getNextLocationOffset(getChildAt(i)) / i < mBaselineAlignedChildIndex])
    // and also add:
    // getLocationOffset(child)
    int childTop = mBaselineChildTop;

    if (mOrientation == VERTICAL) {
        final int majorGravity = mGravity & Gravity.VERTICAL_GRAVITY_MASK;
        if (majorGravity != Gravity.TOP) {
            switch (majorGravity) {
            case Gravity.BOTTOM:
                childTop = getBottom() - getTop() - getPaddingBottom() - mTotalLength;
                break;

            case Gravity.CENTER_VERTICAL:
                childTop += ((getBottom() - getTop() - getPaddingTop() - getPaddingBottom()) - mTotalLength)
                        / 2;
                break;
            }
        }
    }

    LinearLayoutCompat.LayoutParams lp = (LinearLayoutCompat.LayoutParams) child.getLayoutParams();
    return childTop + lp.topMargin + childBaseline;
}