本文整理汇总了Java中android.view.Gravity.HORIZONTAL_GRAVITY_MASK属性的典型用法代码示例。如果您正苦于以下问题:Java Gravity.HORIZONTAL_GRAVITY_MASK属性的具体用法?Java Gravity.HORIZONTAL_GRAVITY_MASK怎么用?Java Gravity.HORIZONTAL_GRAVITY_MASK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.view.Gravity
的用法示例。
在下文中一共展示了Gravity.HORIZONTAL_GRAVITY_MASK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setGravity
/**
* Set the location at which the notification should appear on the screen.
*
* @param gravity
* @param xOffset
* @param yOffset
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public IBuilder setGravity(int gravity, int xOffset, int yOffset) {
// We can resolve the Gravity here by using the Locale for getting
// the layout direction
final int finalGravity;
if (Build.VERSION.SDK_INT >= 14) {
final Configuration config = mContext.getResources()
.getConfiguration();
finalGravity = Gravity.getAbsoluteGravity(gravity, config.getLayoutDirection());
} else {
finalGravity = gravity;
}
mBuilderParams.gravity = finalGravity;
if ((finalGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
mBuilderParams.horizontalWeight = 1.0f;
}
if ((finalGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
mBuilderParams.verticalWeight = 1.0f;
}
mBuilderParams.y = yOffset;
mBuilderParams.x = xOffset;
return this;
}
示例2: updateLeftPositionByGravity
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;
case Gravity.CENTER_HORIZONTAL:
pos.left += ((size > 0) ? size : 0) / 2;
break;
}
}
示例3: computeInsets
/**
* Compute insets.
*
* <pre>
* ______________________
* |_________dx/2_________|
* |......| /'''''\|......|
* |-dx/2-|| View ||-dx/2-|
* |______| \_____/|______|
* |________ dx/2_________|
* </pre>
*
* @param dx the dx the horizontal unfilled space
* @param dy the dy the horizontal unfilled space
*/
@SuppressLint("NewApi")
private void computeInsets(final int dx, final int dy) {
int absoluteGravity = mGravity;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
absoluteGravity = Gravity.getAbsoluteGravity(mGravity, getLayoutDirection());
}
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.LEFT:
mHorizontalInset = 0;
break;
case Gravity.RIGHT:
mHorizontalInset = dx;
break;
case Gravity.CENTER_HORIZONTAL:
default:
mHorizontalInset = dx / 2;
break;
}
switch (absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) {
case Gravity.TOP:
mVerticalInset = 0;
break;
case Gravity.BOTTOM:
mVerticalInset = dy;
break;
case Gravity.CENTER_VERTICAL:
default:
mVerticalInset = dy / 2;
break;
}
}
示例4: resolveGravity
/**
* Return the given gravity value, but if either or both of the axes doesn't have any gravity
* specified, the default value (start or top) is specified. This should be used for children
* that are not anchored to another view or a keyline.
*/
private static int resolveGravity(int gravity) {
if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.NO_GRAVITY) {
gravity |= GravityCompat.START;
}
if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.NO_GRAVITY) {
gravity |= Gravity.TOP;
}
return gravity;
}
示例5: onLayout
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
// HorizontalScrollView is broken for Gravity.RIGHT. So we're fixing it.
autoScrolling = false;
int childWidth = getView().getWidth();
super.onLayout(changed, left, top, right, bottom);
int delta = getView().getWidth() - childWidth;
AdvancedDisplay view = getView();
ScrollableDisplay.LayoutParams p = (LayoutParams) view.getLayoutParams();
int horizontalGravity = p.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
int verticalGravity = p.gravity & Gravity.VERTICAL_GRAVITY_MASK;
if(horizontalGravity == Gravity.RIGHT) {
if(getScrollRange() > 0) {
gravityRight = true;
p.gravity = Gravity.LEFT | verticalGravity;
view.setLayoutParams(p);
super.onLayout(changed, left, top, right, bottom);
}
}
else if(gravityRight) {
if(getScrollRange() == 0) {
gravityRight = false;
p.gravity = Gravity.RIGHT | verticalGravity;
view.setLayoutParams(p);
super.onLayout(changed, left, top, right, bottom);
}
}
if(gravityRight && delta > 0) {
scrollBy(delta, 0);
autoScrolling = true;
}
}
示例6: setGravity
/**
* 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 Gravity}
*
* @attr ref android.R.styleable#Spinner_gravity
*/
public void setGravity(int gravity) {
if (mGravity != gravity) {
if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) {
gravity |= Gravity.LEFT;
}
mGravity = gravity;
requestLayout();
}
}
示例7: onDrawState
@Override
public void onDrawState(EmptyStateRecyclerView rv, Canvas canvas) {
final int width = rv.getMeasuredWidth();
final int height = rv.getMeasuredHeight();
configureImage(width, height);
final int horizontalGravity = Gravity.getAbsoluteGravity(imageGravity,
ViewCompat.getLayoutDirection(rv))&Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravity = imageGravity&Gravity.VERTICAL_GRAVITY_MASK;
// Account for horizontal gravity
float dx;
switch (horizontalGravity) {
case Gravity.CENTER_HORIZONTAL:
dx = (width >> 1) - (image.getWidth() >> 1);
break;
case GravityCompat.END:
dx = width - image.getWidth();
break;
default:
case GravityCompat.START:
dx = 0;
break;
}
// Account for vertical gravity
float dy;
switch (verticalGravity) {
case Gravity.CENTER_VERTICAL:
dy = (height >> 1) - (image.getHeight() >> 1);
break;
case Gravity.BOTTOM:
dy = height - image.getHeight();
break;
default:
case Gravity.TOP:
dy = 0;
break;
}
// Account for the set margins
dx -= getPaddingLeft(); // Left margin
dx += getPaddingRight(); // Right margin
dy += getPaddingTop(); // Top margin
dy -= getPaddingBottom(); // Bottom margin
// Draw bitmap using locations based on gravity
canvas.drawBitmap(image, dx, dy, null);
}
示例8: onPageScrolled
/**
* This method will be invoked when the current page is scrolled, either as part
* of a programmatically initiated smooth scroll or a user initiated touch scroll.
* If you override this method you must call through to the superclass implementation
* (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
* returns.
*
* @param position Position index of the first page currently being displayed.
* Page position+1 will be visible if positionOffset is nonzero.
* @param offset Value from [0, 1) indicating the offset from the page at position.
* @param offsetPixels Value in pixels indicating the offset from position.
*/
protected void onPageScrolled(int position, float offset, int offsetPixels) {
// Offset any decor views if needed - keep them on-screen at all times.
if (mDecorChildCount > 0) {
final int scrollX = getScrollX();
int paddingLeft = getPaddingLeft();
int paddingRight = getPaddingRight();
final int width = getWidth();
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (!lp.isDecor) continue;
final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
int childLeft = 0;
switch (hgrav) {
default:
childLeft = paddingLeft;
break;
case Gravity.LEFT:
childLeft = paddingLeft;
paddingLeft += child.getWidth();
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;
}
childLeft += scrollX;
final int childOffset = childLeft - child.getLeft();
if (childOffset != 0) {
child.offsetLeftAndRight(childOffset);
}
}
}
if (mOnPageChangeListener != null) {
mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
}
if (mInternalPageChangeListener != null) {
mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
}
transformPages();
mCalledSuper = true;
}
示例9: computeInsetsWithGravity
@SuppressLint("RtlHardcoded")
private void computeInsetsWithGravity(View view, Rect insets) {
ViewGroup.LayoutParams lp = view.getLayoutParams();
int gravity = -1;
if (lp instanceof FrameLayout.LayoutParams) {
gravity = ((FrameLayout.LayoutParams) lp).gravity;
}
/**
* 因为该方法执行时机早于 FrameLayout.layoutChildren,
* 而在 {FrameLayout#layoutChildren} 中当 gravity == -1 时会设置默认值为 Gravity.TOP | Gravity.LEFT,
* 所以这里也要同样设置
*/
if (gravity == -1) {
gravity = Gravity.TOP | Gravity.LEFT;
}
if (lp.width != FrameLayout.LayoutParams.MATCH_PARENT) {
int horizontalGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
switch (horizontalGravity) {
case Gravity.LEFT:
insets.right = 0;
break;
case Gravity.RIGHT:
insets.left = 0;
break;
}
}
if (lp.height != FrameLayout.LayoutParams.MATCH_PARENT) {
int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch (verticalGravity) {
case Gravity.TOP:
insets.bottom = 0;
break;
case Gravity.BOTTOM:
insets.top = 0;
break;
}
}
}
示例10: onDraw
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mPageCount == 0) {
return;
}
float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
float totalLeft;
boolean fillHorizontal = false;
switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
totalLeft = (getWidth() - totalWidth) / 2;
break;
case Gravity.RIGHT:
totalLeft = getWidth() - getPaddingRight() - totalWidth;
break;
case Gravity.FILL_HORIZONTAL:
totalLeft = getPaddingLeft();
fillHorizontal = true;
break;
default:
totalLeft = getPaddingLeft();
}
switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) {
case Gravity.CENTER_VERTICAL:
mTempRectF.top = (int) (getHeight() - mTabHeight) / 2;
break;
case Gravity.BOTTOM:
mTempRectF.top = getHeight() - getPaddingBottom() - mTabHeight;
break;
default:
mTempRectF.top = getPaddingTop();
}
mTempRectF.bottom = mTempRectF.top + mTabHeight;
float tabWidth = mTabWidth;
if (fillHorizontal) {
tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft()
- (mPageCount - 1) * mTabSpacing) / mPageCount;
}
for (int i = 0; i < mPageCount; i++) {
mTempRectF.left = totalLeft + (i * (tabWidth + mTabSpacing));
mTempRectF.right = mTempRectF.left + tabWidth;
canvas.drawRect(mTempRectF, i < mCurrentPage
? mPrevTabPaint
: (i > mCurrentPage
? mNextTabPaint
: (i == mPageCount - 1
? mSelectedLastTabPaint
: mSelectedTabPaint)));
}
}
示例11: onDraw
@Override
protected void onDraw(Canvas canvas) {
// If there's text of any sort resort to CompoundButton#onDraw
if (getText() != null && getText().length() > 0 ||
getTextOff() != null && getTextOff().length() > 0 ||
getTextOff() != null && getTextOn().length() > 0) {
super.onDraw(canvas);
}
// Otherwise override CompoundButton#onDraw entirely to allow properly aligned image toggles
else {
final Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(this);
if (buttonDrawable != null) {
final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
final int horizontalGravity = getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK;
final int drawableHeight = buttonDrawable.getIntrinsicHeight();
final int drawableWidth = buttonDrawable.getIntrinsicWidth();
final int top;
switch (verticalGravity) {
case Gravity.BOTTOM:
top = getHeight() - drawableHeight;
break;
case Gravity.CENTER_VERTICAL:
top = (getHeight() - drawableHeight) / 2;
break;
default:
top = 0;
}
final int left;
switch (horizontalGravity) {
case Gravity.RIGHT:
case Gravity.END:
left = getWidth() - drawableWidth;
break;
case Gravity.CENTER_HORIZONTAL:
left = (getWidth() - drawableWidth) / 2;
break;
default:
left = 0;
}
final int bottom = top + drawableHeight;
final int right = left + drawableWidth;
buttonDrawable.setBounds(left, top, right, bottom);
final Drawable background = getBackground();
if (Build.VERSION.SDK_INT > 21 && background != null) {
background.setHotspotBounds(left, top, right, bottom);
}
buttonDrawable.draw(canvas);
}
}
}
示例12: onLayout
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
int paddingBottom = getKeyboardHeight() <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow ? captionEditText.getEmojiPadding() : 0;
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int width = child.getMeasuredWidth();
final int height = child.getMeasuredHeight();
int childLeft;
int childTop;
int gravity = lp.gravity;
if (gravity == -1) {
gravity = Gravity.TOP | Gravity.LEFT;
}
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = r - width - lp.rightMargin;
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin;
}
switch (verticalGravity) {
case Gravity.TOP:
childTop = lp.topMargin;
break;
case Gravity.CENTER_VERTICAL:
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
if (child == mentionListView) {
if (!captionEditText.isPopupShowing() && !captionEditText.isKeyboardVisible() && captionEditText.getEmojiPadding() == 0) {
childTop += AndroidUtilities.dp(400);
} else {
childTop -= captionEditText.getMeasuredHeight();
}
} else if (child == captionEditText) {
if (!captionEditText.isPopupShowing() && !captionEditText.isKeyboardVisible() && captionEditText.getEmojiPadding() == 0) {
childTop += AndroidUtilities.dp(400);
}
} else if (child == pickerView || child == captionTextViewNew || child == captionTextViewOld) {
if (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible()) {
childTop += AndroidUtilities.dp(400);
}
} else if (captionEditText.isPopupView(child)) {
if (AndroidUtilities.isInMultiwindow) {
childTop = captionEditText.getTop() - child.getMeasuredHeight() + AndroidUtilities.dp(1);
} else {
childTop = captionEditText.getBottom();
}
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
notifyHeightChanged();
}
示例13: testTextAlign
@Test
public void testTextAlign() {
ReactEditText view = mManager.createViewInstance(mThemedContext);
int defaultGravity = view.getGravity();
int defaultHorizontalGravity = defaultGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
int defaultVerticalGravity = defaultGravity & Gravity.VERTICAL_GRAVITY_MASK;
// Theme
assertThat(view.getGravity()).isNotEqualTo(Gravity.NO_GRAVITY);
// TextAlign
mManager.updateProperties(view, buildStyles("textAlign", "left"));
assertThat(view.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK).isEqualTo(Gravity.LEFT);
mManager.updateProperties(view, buildStyles("textAlign", "right"));
assertThat(view.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK).isEqualTo(Gravity.RIGHT);
mManager.updateProperties(view, buildStyles("textAlign", "center"));
assertThat(view.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK).isEqualTo(Gravity.CENTER_HORIZONTAL);
mManager.updateProperties(view, buildStyles("textAlign", null));
assertThat(view.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK).isEqualTo(defaultHorizontalGravity);
// TextAlignVertical
mManager.updateProperties(view, buildStyles("textAlignVertical", "top"));
assertThat(view.getGravity() & Gravity.VERTICAL_GRAVITY_MASK).isEqualTo(Gravity.TOP);
mManager.updateProperties(view, buildStyles("textAlignVertical", "bottom"));
assertThat(view.getGravity() & Gravity.VERTICAL_GRAVITY_MASK).isEqualTo(Gravity.BOTTOM);
mManager.updateProperties(view, buildStyles("textAlignVertical", "center"));
assertThat(view.getGravity() & Gravity.VERTICAL_GRAVITY_MASK).isEqualTo(Gravity.CENTER_VERTICAL);
mManager.updateProperties(view, buildStyles("textAlignVertical", null));
assertThat(view.getGravity() & Gravity.VERTICAL_GRAVITY_MASK).isEqualTo(defaultVerticalGravity);
// TextAlign + TextAlignVertical
mManager.updateProperties(
view,
buildStyles("textAlign", "center", "textAlignVertical", "center"));
assertThat(view.getGravity()).isEqualTo(Gravity.CENTER);
mManager.updateProperties(
view,
buildStyles("textAlign", "right", "textAlignVertical", "bottom"));
assertThat(view.getGravity()).isEqualTo(Gravity.RIGHT | Gravity.BOTTOM);
mManager.updateProperties(
view,
buildStyles("textAlign", null, "textAlignVertical", null));
assertThat(view.getGravity()).isEqualTo(defaultGravity);
}
示例14: ReactTextView
public ReactTextView(Context context) {
super(context);
mDefaultGravityHorizontal =
getGravity() & (Gravity.HORIZONTAL_GRAVITY_MASK | Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK);
mDefaultGravityVertical = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
}
示例15: makeCubicGradientScrimDrawable
/**
* Creates an approximated cubic gradient using a multi-stop linear gradient. See
* <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
* details.
*/
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
// Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
int cacheKeyHash = baseColor;
cacheKeyHash = 31 * cacheKeyHash + numStops;
cacheKeyHash = 31 * cacheKeyHash + gravity;
Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
if (cachedGradient != null) {
return cachedGradient;
}
numStops = Math.max(numStops, 2);
PaintDrawable paintDrawable = new PaintDrawable();
paintDrawable.setShape(new RectShape());
final int[] stopColors = new int[numStops];
int red = Color.red(baseColor);
int green = Color.green(baseColor);
int blue = Color.blue(baseColor);
int alpha = Color.alpha(baseColor);
for (int i = 0; i < numStops; i++) {
float x = i * 1f / (numStops - 1);
float opacity = MathUtil.constrain(0, 1, (float) Math.pow(x, 3));
stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
}
final float x0, x1, y0, y1;
switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.LEFT: x0 = 1; x1 = 0; break;
case Gravity.RIGHT: x0 = 0; x1 = 1; break;
default: x0 = 0; x1 = 0; break;
}
switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
case Gravity.TOP: y0 = 1; y1 = 0; break;
case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
default: y0 = 0; y1 = 0; break;
}
paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
@Override
public Shader resize(int width, int height) {
return new LinearGradient(
width * x0,
height * y0,
width * x1,
height * y1,
stopColors, null,
Shader.TileMode.CLAMP);
}
});
cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
return paintDrawable;
}