Java Code Examples for android.view.Gravity#RELATIVE_HORIZONTAL_GRAVITY_MASK
The following examples show how to use
android.view.Gravity#RELATIVE_HORIZONTAL_GRAVITY_MASK .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ForegroundDelegate.java From ForegroundViews with Apache License 2.0 | 6 votes |
public void setForegroundGravity(int foregroundGravity) { if (mForegroundGravity != foregroundGravity) { if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { foregroundGravity |= Gravity.START; } if ((foregroundGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) { foregroundGravity |= Gravity.TOP; } mForegroundGravity = foregroundGravity; if (mForegroundGravity == Gravity.FILL && mForeground != null) { Rect padding = new Rect(); mForeground.getPadding(padding); } mView.requestLayout(); } }
Example 2
Source File: LinearLayout.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Describes how the child views are positioned. Defaults to GRAVITY_TOP. If * this layout has a VERTICAL orientation, this controls where all the child * views are placed if there is extra vertical space. If this layout has a * HORIZONTAL orientation, this controls the alignment of the children. * * @param gravity See {@link android.view.Gravity} * * @attr ref android.R.styleable#LinearLayout_gravity */ @android.view.RemotableViewMethod public void setGravity(int gravity) { if (mGravity != gravity) { if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { gravity |= Gravity.START; } if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) { gravity |= Gravity.TOP; } mGravity = gravity; requestLayout(); } }
Example 3
Source File: TextViewAttrsHelper.java From FastTextView with Apache License 2.0 | 6 votes |
private static Layout.Alignment getAlignmentByGravity(int gravity) { switch (gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.START: return Layout.Alignment.ALIGN_NORMAL; case Gravity.END: return Layout.Alignment.ALIGN_OPPOSITE; case Gravity.LEFT: return Layout.Alignment.ALIGN_LEFT; case Gravity.RIGHT: return Layout.Alignment.ALIGN_RIGHT; case Gravity.CENTER_HORIZONTAL: return Layout.Alignment.ALIGN_CENTER; default: return Layout.Alignment.ALIGN_NORMAL; } }
Example 4
Source File: TextViewAttrsHelper.java From FastTextView with Apache License 2.0 | 6 votes |
/** * Sets the horizontal alignment of the text and the * vertical gravity that will be used when there is extra space * in the TextView beyond what is required for the text itself. * * @see android.view.Gravity */ public boolean setGravity(int gravity) { if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { gravity |= Gravity.START; } if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) { gravity |= Gravity.TOP; } boolean newLayout = false; if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) != (mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK)) { newLayout = true; } if (gravity != mGravity) { newLayout = true; } mGravity = gravity; return newLayout; }
Example 5
Source File: ForegroundLinearLayout.java From android-proguards with Apache License 2.0 | 6 votes |
/** * Describes how the foreground is positioned. Defaults to START and TOP. * * @param foregroundGravity See {@link android.view.Gravity} * @see #getForegroundGravity() */ public void setForegroundGravity(int foregroundGravity) { if (mForegroundGravity != foregroundGravity) { if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { foregroundGravity |= Gravity.START; } if ((foregroundGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) { foregroundGravity |= Gravity.TOP; } mForegroundGravity = foregroundGravity; if (mForegroundGravity == Gravity.FILL && mForeground != null) { Rect padding = new Rect(); mForeground.getPadding(padding); } requestLayout(); } }
Example 6
Source File: ForegroundLinearLayout.java From RetailStore with Apache License 2.0 | 6 votes |
/** * Describes how the foreground is positioned. Defaults to START and TOP. * * @param foregroundGravity See {@link Gravity} * * @see #getForegroundGravity() */ public void setForegroundGravity(int foregroundGravity) { if (mForegroundGravity != foregroundGravity) { if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { foregroundGravity |= Gravity.START; } if ((foregroundGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) { foregroundGravity |= Gravity.TOP; } mForegroundGravity = foregroundGravity; if (mForegroundGravity == Gravity.FILL && mForeground != null) { Rect padding = new Rect(); mForeground.getPadding(padding); } requestLayout(); } }
Example 7
Source File: ForegroundDelegate.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 6 votes |
public void setForegroundGravity(View view, int foregroundGravity) { if (view != null) { if (mForegroundGravity != foregroundGravity) { if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { foregroundGravity |= Gravity.START; } if ((foregroundGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) { foregroundGravity |= Gravity.TOP; } mForegroundGravity = foregroundGravity; if (mForegroundGravity == Gravity.FILL && mForeground != null) { Rect padding = new Rect(); mForeground.getPadding(padding); } view.requestLayout(); } } }
Example 8
Source File: ReactEditText.java From react-native-GPay with MIT License | 6 votes |
public ReactEditText(Context context) { super(context); setFocusableInTouchMode(false); mReactBackgroundManager = new ReactViewBackgroundManager(this); mInputMethodManager = (InputMethodManager) Assertions.assertNotNull(getContext().getSystemService(Context.INPUT_METHOD_SERVICE)); mDefaultGravityHorizontal = getGravity() & (Gravity.HORIZONTAL_GRAVITY_MASK | Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK); mDefaultGravityVertical = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; mNativeEventCount = 0; mMostRecentEventCount = 0; mIsSettingTextFromJS = false; mIsJSSettingFocus = false; mBlurOnSubmit = null; mDisableFullscreen = false; mListeners = null; mTextWatcherDelegator = null; mStagedInputType = getInputType(); mKeyListener = new InternalKeyListener(); mScrollWatcher = null; }
Example 9
Source File: WheelView.java From X-Alarm with GNU Affero General Public License v3.0 | 6 votes |
/** * Describes how the foreground is positioned. Defaults to START and TOP. * * @param foregroundGravity See {@link android.view.Gravity} * * @see #getForegroundGravity() */ public void setForegroundGravity(int foregroundGravity) { if (mForegroundGravity != foregroundGravity) { if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { foregroundGravity |= Gravity.START; } if ((foregroundGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) { foregroundGravity |= Gravity.TOP; } mForegroundGravity = foregroundGravity; if (mForegroundGravity == Gravity.FILL && mWheelForeground != null) { Rect padding = new Rect(); mWheelForeground.getPadding(padding); } requestLayout(); } }
Example 10
Source File: EditTextSpec.java From litho with Apache License 2.0 | 6 votes |
private static Layout.Alignment getAlignment(int gravity) { final Layout.Alignment alignment; // This was copied from TextSpec for handling text alignment switch (gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.START: alignment = ALIGN_NORMAL; break; case Gravity.END: alignment = ALIGN_OPPOSITE; break; case Gravity.LEFT: // unsupported, default to normal alignment = ALIGN_NORMAL; break; case Gravity.RIGHT: // unsupported, default to opposite alignment = ALIGN_OPPOSITE; break; case Gravity.CENTER_HORIZONTAL: alignment = ALIGN_CENTER; break; default: alignment = textAlignment; break; } return alignment; }
Example 11
Source File: ShadowView.java From YCCardView with Apache License 2.0 | 6 votes |
@Override public void setForegroundGravity(int foregroundGravity) { if (foregroundDrawGravity != foregroundGravity) { if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { foregroundGravity = foregroundGravity | Gravity.START; } if ((foregroundGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) { foregroundGravity = foregroundGravity | Gravity.TOP; } foregroundDrawGravity = foregroundGravity; if (foregroundDrawGravity == Gravity.FILL && foregroundDrawable != null) { Rect padding = new Rect(); foregroundDrawable.getPadding(padding); } requestLayout(); } }
Example 12
Source File: FlowLayoutA.java From Android-Next with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void setGravity(int gravity) { if (mGravity != gravity) { if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { gravity |= isIcs() ? Gravity.START : Gravity.LEFT; } if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) { gravity |= Gravity.TOP; } mGravity = gravity; requestLayout(); } }
Example 13
Source File: ClickableSpanUtil.java From FastTextView with Apache License 2.0 | 5 votes |
private static int getOffsetForHorizontal(View view, Layout layout, int x, int line) { if (view.getWidth() > layout.getWidth()) { if (view instanceof FastTextView) { int gravity = ((FastTextView) view).getGravity(); int translateX; int horizontalGravity = gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK; switch (horizontalGravity) { default: case Gravity.LEFT: translateX = view.getPaddingLeft(); break; case Gravity.CENTER_HORIZONTAL: translateX = view.getPaddingLeft() + (((FastTextView) view).getInnerWidth() - layout .getWidth()) / 2; break; case Gravity.RIGHT: translateX = view.getPaddingLeft() + ((FastTextView) view).getInnerWidth() - layout .getWidth(); break; } x -= translateX; } } try { return layout.getOffsetForHorizontal(line, x); } catch (Throwable e) { e.printStackTrace(); } return layout.getLineEnd(line); }
Example 14
Source File: AutoLinearLayout.java From mvvm-template with GNU General Public License v3.0 | 5 votes |
/** * Describes how the child views are positioned. Defaults to GRAVITY_TOP. If * this layout has a VERTICAL orientation, this controls where all the child * views are placed if there is extra vertical space. If this layout has a * HORIZONTAL orientation, this controls the alignment of the children. * * @param gravity * See {@link Gravity} */ private void setGravity(int gravity) { if (mGravity != gravity) { if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { gravity |= GravityCompat.START; } if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) { gravity |= Gravity.TOP; } mGravity = gravity; requestLayout(); } }
Example 15
Source File: ReactTextView.java From react-native-GPay with MIT License | 5 votes |
public ReactTextView(Context context) { super(context); mReactBackgroundManager = new ReactViewBackgroundManager(this); mDefaultGravityHorizontal = getGravity() & (Gravity.HORIZONTAL_GRAVITY_MASK | Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK); mDefaultGravityVertical = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; }
Example 16
Source File: RelativeLayout.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@android.view.RemotableViewMethod public void setHorizontalGravity(int horizontalGravity) { final int gravity = horizontalGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK; if ((mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) != gravity) { mGravity = (mGravity & ~Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) | gravity; requestLayout(); } }
Example 17
Source File: LinearLayout.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@android.view.RemotableViewMethod public void setHorizontalGravity(int horizontalGravity) { final int gravity = horizontalGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK; if ((mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) != gravity) { mGravity = (mGravity & ~Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) | gravity; requestLayout(); } }
Example 18
Source File: FragmentBreadCrumbs.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // Eventually we should implement our own layout of the views, rather than relying on // a single linear layout. final int childCount = getChildCount(); if (childCount == 0) { return; } final View child = getChildAt(0); final int childTop = mPaddingTop; final int childBottom = mPaddingTop + child.getMeasuredHeight() - mPaddingBottom; int childLeft; int childRight; final int layoutDirection = getLayoutDirection(); final int horizontalGravity = mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK; switch (Gravity.getAbsoluteGravity(horizontalGravity, layoutDirection)) { case Gravity.RIGHT: childRight = mRight - mLeft - mPaddingRight; childLeft = childRight - child.getMeasuredWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = mPaddingLeft + (mRight - mLeft - child.getMeasuredWidth()) / 2; childRight = childLeft + child.getMeasuredWidth(); break; case Gravity.LEFT: default: childLeft = mPaddingLeft; childRight = childLeft + child.getMeasuredWidth(); break; } if (childLeft < mPaddingLeft) { childLeft = mPaddingLeft; } if (childRight > mRight - mLeft - mPaddingRight) { childRight = mRight - mLeft - mPaddingRight; } child.layout(childLeft, childTop, childRight, childBottom); }
Example 19
Source File: RelativeLayout.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Describes how the child views are positioned. Defaults to * <code>Gravity.START | Gravity.TOP</code>. * * <p>Note that since RelativeLayout considers the positioning of each child * relative to one another to be significant, setting gravity will affect * the positioning of all children as a single unit within the parent. * This happens after children have been relatively positioned.</p> * * @param gravity See {@link android.view.Gravity} * * @see #setHorizontalGravity(int) * @see #setVerticalGravity(int) * * @attr ref android.R.styleable#RelativeLayout_gravity */ @android.view.RemotableViewMethod public void setGravity(int gravity) { if (mGravity != gravity) { if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) { gravity |= Gravity.START; } if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) { gravity |= Gravity.TOP; } mGravity = gravity; requestLayout(); } }
Example 20
Source File: LinearLayout.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Position the children during a layout pass if the orientation of this * LinearLayout is set to {@link #VERTICAL}. * * @see #getOrientation() * @see #setOrientation(int) * @see #onLayout(boolean, int, int, int, int) * @param left * @param top * @param right * @param bottom */ void layoutVertical(int left, int top, int right, int bottom) { final int paddingLeft = mPaddingLeft; int childTop; int childLeft; // Where right end of child should go final int width = right - left; int childRight = width - mPaddingRight; // Space available for child int childSpace = width - paddingLeft - mPaddingRight; final int count = getVirtualChildCount(); final int majorGravity = mGravity & Gravity.VERTICAL_GRAVITY_MASK; final int minorGravity = mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK; switch (majorGravity) { case Gravity.BOTTOM: // mTotalLength contains the padding already childTop = mPaddingTop + bottom - top - mTotalLength; break; // mTotalLength contains the padding already case Gravity.CENTER_VERTICAL: childTop = mPaddingTop + (bottom - top - mTotalLength) / 2; break; case Gravity.TOP: default: childTop = mPaddingTop; break; } for (int i = 0; i < count; i++) { final View child = getVirtualChildAt(i); if (child == null) { childTop += measureNullChild(i); } else if (child.getVisibility() != GONE) { final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); int gravity = lp.gravity; if (gravity < 0) { gravity = minorGravity; } final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: childLeft = paddingLeft + ((childSpace - childWidth) / 2) + lp.leftMargin - lp.rightMargin; break; case Gravity.RIGHT: childLeft = childRight - childWidth - lp.rightMargin; break; case Gravity.LEFT: default: childLeft = paddingLeft + lp.leftMargin; break; } if (hasDividerBeforeChildAt(i)) { childTop += mDividerHeight; } childTop += lp.topMargin; setChildFrame(child, childLeft, childTop + getLocationOffset(child), childWidth, childHeight); childTop += childHeight + lp.bottomMargin + getNextLocationOffset(child); i += getChildrenSkipCount(child, i); } } }