List of usage examples for android.view Gravity HORIZONTAL_GRAVITY_MASK
int HORIZONTAL_GRAVITY_MASK
To view the source code for android.view Gravity HORIZONTAL_GRAVITY_MASK.
Click Source Link
From source file:com.actionbarsherlock.internal.widget.IcsSpinner.java
/** * Creates and positions all views for this Spinner. * * @param delta Change in the selected position. +1 moves selection is moving to the right, * so views are scrolling to the left. -1 means selection is moving to the left. *//*from w w w . j a v a 2 s.c om*/ @Override void layout(int delta, boolean animate) { int childrenLeft = mSpinnerPadding.left; int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right; if (mDataChanged) { handleDataChanged(); } // Handle the empty set by removing all views if (mItemCount == 0) { resetList(); return; } if (mNextSelectedPosition >= 0) { setSelectedPositionInt(mNextSelectedPosition); } recycleAllViews(); // Clear out old views removeAllViewsInLayout(); // Make selected view and position it mFirstPosition = mSelectedPosition; View sel = makeAndAddView(mSelectedPosition); int width = sel.getMeasuredWidth(); int selectedOffset = childrenLeft; switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2); break; case Gravity.RIGHT: selectedOffset = childrenLeft + childrenWidth - width; break; } sel.offsetLeftAndRight(selectedOffset); // Flush any cached views that did not get reused above mRecycler.clear(); invalidate(); checkSelectionChanged(); mDataChanged = false; mNeedSync = false; setNextSelectedPositionInt(mSelectedPosition); }
From source file:android.support.designox.widget.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom; break;/*from w ww . j ava 2 s . c om*/ case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; break; } switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; break; } switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:com.amitupadhyay.aboutexample.util.CollapsingTextHelper.java
private void calculateBaseOffsets() { // We then calculate the collapsed text size, using the same logic mTextPaint.setTextSize(mCollapsedTextSize); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom; break;/*from w w w .j a v a 2 s. c om*/ case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; break; } switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } mTextPaint.setTextSize(mExpandedTextSize); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; break; } switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); }
From source file:android.support.v7.internal.widget.SpinnerCompat.java
/** * Describes how the selected item view is positioned. Currently only the horizontal component * is used. The default is determined by the current theme. * * @param gravity See {@link android.view.Gravity} *///from w w w . ja v a2 s . c o m public void setGravity(int gravity) { if (mGravity != gravity) { if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) { gravity |= GravityCompat.START; } mGravity = gravity; requestLayout(); } }
From source file:com.tr4android.support.extension.widget.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); mCollapsedTextHeight = -mTextPaint.ascent(); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom - mCollapsedTextOffsetBottom; break;//from w w w . j a v a 2 s . com case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent() + mCollapsedTextOffsetTop; break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset - (mCollapsedTextOffsetBottom / 2) + (mCollapsedTextOffsetTop / 2); break; } switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); mExpandedTextHeight = -mTextPaint.ascent(); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom - mExpandedTextOffsetBottom; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent() + mExpandedTextOffsetTop; break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset - (mExpandedTextOffsetBottom / 2) + (mExpandedTextOffsetTop / 2); break; } switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:net.grobas.widget.AutoLinearLayout.java
private void updateLeftPositionByGravity(ViewPosition pos, int size, int gravity) { switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case GravityCompat.END: pos.left += (size > 0) ? size : 0; break;// ww w . j a va 2 s .c om case Gravity.CENTER_HORIZONTAL: pos.left += ((size > 0) ? size : 0) / 2; break; } }
From source file:com.quran.labs.androidquran.widgets.spinner.SpinnerCompat.java
/** * Creates and positions all views for this Spinner. * * @param delta Change in the selected position. +1 means selection is moving to the right, so * views are scrolling to the left. -1 means selection is moving to the left. *//*from ww w. j a va 2s.co m*/ @SuppressLint("RtlHardcoded") @Override void layout(int delta, boolean animate) { int childrenLeft = mSpinnerPadding.left; int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right; if (mDataChanged) { handleDataChanged(); } // Handle the empty set by removing all views if (mItemCount == 0) { resetList(); return; } if (mNextSelectedPosition >= 0) { setSelectedPositionInt(mNextSelectedPosition); } recycleAllViews(); // Clear out old views removeAllViewsInLayout(); // Make selected view and position it mFirstPosition = mSelectedPosition; if (mAdapter != null) { View sel = makeView(mSelectedPosition, true); int width = sel.getMeasuredWidth(); int selectedOffset = childrenLeft; final int layoutDirection = ViewCompat.getLayoutDirection(this); final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2); break; case Gravity.RIGHT: selectedOffset = childrenLeft + childrenWidth - width; break; } sel.offsetLeftAndRight(selectedOffset); } // Flush any cached views that did not get reused above mRecycler.clear(); invalidate(); checkSelectionChanged(); mDataChanged = false; mNeedSync = false; setNextSelectedPositionInt(mSelectedPosition); }
From source file:android.support.v7.internal.widget.SpinnerCompat.java
/** * Creates and positions all views for this Spinner. * * @param delta Change in the selected position. +1 means selection is moving to the right, so * views are scrolling to the left. -1 means selection is moving to the left. *//* w w w. j av a 2 s . c om*/ @Override void layout(int delta, boolean animate) { int childrenLeft = mSpinnerPadding.left; int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right; if (mDataChanged) { handleDataChanged(); } // Handle the empty set by removing all views if (mItemCount == 0) { resetList(); return; } if (mNextSelectedPosition >= 0) { setSelectedPositionInt(mNextSelectedPosition); } recycleAllViews(); // Clear out old views removeAllViewsInLayout(); // Make selected view and position it mFirstPosition = mSelectedPosition; if (mAdapter != null) { View sel = makeView(mSelectedPosition, true); int width = sel.getMeasuredWidth(); int selectedOffset = childrenLeft; final int layoutDirection = ViewCompat.getLayoutDirection(this); final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2); break; case Gravity.RIGHT: selectedOffset = childrenLeft + childrenWidth - width; break; } sel.offsetLeftAndRight(selectedOffset); } // Flush any cached views that did not get reused above mRecycler.clear(); invalidate(); checkSelectionChanged(); mDataChanged = false; mNeedSync = false; setNextSelectedPositionInt(mSelectedPosition); }
From source file:com.muzakki.ahmad.widget.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); calculateUsingSubSize(mCollapsedSubSize); float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2); if (mSub != null) { float subHeight = mSubPaint.descent() - mSubPaint.ascent(); float subOffset = (subHeight / 2) - mSubPaint.descent(); float offset = ((mCollapsedBounds.height() - (textHeight + subHeight)) / 3); mCollapsedDrawY = mCollapsedBounds.top + offset - mTextPaint.ascent(); mCollapsedSubY = mCollapsedBounds.top + (offset * 2) + textHeight - mSubPaint.ascent(); } else { // title only mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; }//from w w w .j a v a2 s . c om float width = mText != null ? mTextPaint.measureText(mText, 0, mText.length()) : 0; float subWidth = mSub != null ? mSubPaint.measureText(mSub, 0, mSub.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); mCollapsedDrawSubX = mCollapsedBounds.centerX() - (subWidth / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; mCollapsedDrawSubX = mCollapsedBounds.right - subWidth; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; mCollapsedDrawSubX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); calculateUsingSubSize(mExpandedSubSize); textHeight = mTextPaint.descent() - mTextPaint.ascent(); textOffset = (textHeight / 2); if (mSub != null) { float subHeight = mSubPaint.descent() - mSubPaint.ascent(); float subOffset = (subHeight / 2); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; mExpandedSubY = mExpandedDrawY + subOffset - mSubPaint.ascent(); } else { // title only mExpandedDrawY = mExpandedBounds.centerY() + textOffset; } width = mText != null ? mTextPaint.measureText(mText, 0, mText.length()) : 0; subWidth = mSub != null ? mSubPaint.measureText(mSub, 0, mSub.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); mExpandedDrawSubX = mExpandedBounds.centerX() - (subWidth / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; mExpandedDrawSubX = mExpandedBounds.right - subWidth; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; mExpandedDrawSubX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:com.cyanogenmod.filemanager.ui.widgets.DrawerLayout.java
/** * @param gravity the gravity of the child to return. If specified as a * relative value, it will be resolved according to the current * layout direction.//from w ww . j ava 2 s .co m * @return the drawer with the specified gravity */ View findDrawerWithGravity(int gravity) { final int absHorizGravity = Gravity.getAbsoluteGravity(gravity, this.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final int childAbsGravity = getDrawerViewAbsoluteGravity(child); if ((childAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == absHorizGravity) { return child; } } return null; }