本文整理汇总了Java中android.view.Gravity.VERTICAL_GRAVITY_MASK属性的典型用法代码示例。如果您正苦于以下问题:Java Gravity.VERTICAL_GRAVITY_MASK属性的具体用法?Java Gravity.VERTICAL_GRAVITY_MASK怎么用?Java Gravity.VERTICAL_GRAVITY_MASK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.view.Gravity
的用法示例。
在下文中一共展示了Gravity.VERTICAL_GRAVITY_MASK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContentStartV
protected int getContentStartV(int containerTop, int containerBottom, int contentWillSize, int contentMarginTop, int contentMarginBottom, int gravity) {
if (gravity != -1 || gravity != 0) {
int start;
final int mask = Gravity.VERTICAL_GRAVITY_MASK;
final int maskCenter = Gravity.CENTER_VERTICAL;
final int maskEnd = Gravity.BOTTOM;
final int okGravity = gravity & mask;
if (maskCenter == okGravity) {//center
start = containerTop + (containerBottom - containerTop - (contentWillSize + contentMarginBottom - contentMarginTop)) / 2;
} else if (maskEnd == okGravity) {//end
start = containerBottom - contentWillSize - contentMarginBottom;
} else {//start
start = containerTop + contentMarginTop;
}
return start;
}
return containerTop + contentMarginTop;
}
示例2: onDraw
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mButtonDrawable != null) {
mButtonDrawable.setState(getDrawableState());
final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
final int height = mButtonDrawable.getIntrinsicHeight();
int y = 0;
switch (verticalGravity) {
case Gravity.BOTTOM:
y = getHeight() - height;
break;
case Gravity.CENTER_VERTICAL:
y = (getHeight() - height) / 2;
break;
}
int buttonWidth = mButtonDrawable.getIntrinsicWidth();
int buttonLeft = (getWidth() - buttonWidth) / 2;
mButtonDrawable.setBounds(buttonLeft, y, buttonLeft + buttonWidth, y + height);
mButtonDrawable.draw(canvas);
}
}
示例3: addView
@Override
public void addView(View child, int index, final ViewGroup.LayoutParams params) {
if (child instanceof EditText) {
// Make sure that the EditText is vertically at the bottom, so that it sits on the
// EditText's underline
FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(params);
flp.gravity = Gravity.CENTER_VERTICAL | (flp.gravity & ~Gravity.VERTICAL_GRAVITY_MASK);
mInputFrame.addView(child, flp);
// Now use the EditText's LayoutParams as our own and update them to make enough space
// for the label
mInputFrame.setLayoutParams(params);
updateInputLayoutMargins();
setEditText((EditText) child);
} else {
// Carry on adding the View...
super.addView(child, index, params);
}
}
示例4: 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;
}
}
示例5: updateTopPositionByGravity
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;
case Gravity.CENTER_VERTICAL:
pos.top += ((size > 0) ? size : 0) / 2;
break;
}
}
示例6: VerticalTextView
public VerticalTextView(Context context, AttributeSet attrs){
super(context, attrs);
final int gravity = getGravity();
if (Gravity.isVertical(gravity) && (gravity&Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
setGravity((gravity&Gravity.HORIZONTAL_GRAVITY_MASK) | Gravity.TOP);
topDown = false;
} else {
topDown = true;
}
}
示例7: VerticalTextView
public VerticalTextView(Context context, AttributeSet attrs){
super(context, attrs);
final int gravity = getGravity();
if(Gravity.isVertical(gravity) && (gravity&Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
setGravity((gravity&Gravity.HORIZONTAL_GRAVITY_MASK) | Gravity.TOP);
topDown = false;
}else
topDown = true;
}
示例8: 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;
}
}
}
示例9: 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);
}
示例10: onDrawState
@Override
public void onDrawState(EmptyStateRecyclerView rv, Canvas canvas) {
final int width = rv.getMeasuredWidth();
final int height = rv.getMeasuredHeight();
configureTextLayouts(width);
// Account for vertical text gravity
final int verticalGravity = textGravity&Gravity.VERTICAL_GRAVITY_MASK;
float dy;
switch (verticalGravity) {
case Gravity.CENTER_VERTICAL:
dy = (height >> 1) - ((int)getFullTextHeight() >> 1);
break;
case Gravity.BOTTOM:
dy = height - getFullTextHeight();
break;
default:
case Gravity.TOP:
dy = 0;
break;
}
dy += getPaddingTop();
final int horizontalGravity = Gravity.getAbsoluteGravity(textGravity,
ViewCompat.getLayoutDirection(rv))&Gravity.HORIZONTAL_GRAVITY_MASK;
// Draw the title text
canvas.save();
canvas.translate(
getDx(width, horizontalGravity, titlePaint, titleLayout),
dy);
this.titleLayout.draw(canvas);
canvas.restore();
// Add spacing for under the text with the title spacing
dy += titleLayout.getHeight() + titleSpacing;
// Draw the subtitle text under the title text
canvas.save();
canvas.translate(
getDx(width, horizontalGravity, subtitlePaint, subtitleLayout),
dy);
this.subtitleLayout.draw(canvas);
canvas.restore();
}
示例11: onLayout
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
wasLayout = true;
int opticalInsetLeft = 0;
int opticalInsetRight = 0;
if (mThumbDrawable != null) {
final Rect trackPadding = mTempRect;
if (mTrackDrawable != null) {
mTrackDrawable.getPadding(trackPadding);
} else {
trackPadding.setEmpty();
}
final Insets insets = Insets.NONE;
opticalInsetLeft = Math.max(0, insets.left - trackPadding.left);
opticalInsetRight = Math.max(0, insets.right - trackPadding.right);
}
final int switchRight;
final int switchLeft;
if (LocaleController.isRTL) {
switchLeft = getPaddingLeft() + opticalInsetLeft;
switchRight = switchLeft + mSwitchWidth - opticalInsetLeft - opticalInsetRight;
} else {
switchRight = getWidth() - getPaddingRight() - opticalInsetRight;
switchLeft = switchRight - mSwitchWidth + opticalInsetLeft + opticalInsetRight;
}
final int switchTop;
final int switchBottom;
switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) {
default:
case Gravity.TOP:
switchTop = getPaddingTop();
switchBottom = switchTop + mSwitchHeight;
break;
case Gravity.CENTER_VERTICAL:
switchTop = (getPaddingTop() + getHeight() - getPaddingBottom()) / 2 - mSwitchHeight / 2;
switchBottom = switchTop + mSwitchHeight;
break;
case Gravity.BOTTOM:
switchBottom = getHeight() - getPaddingBottom();
switchTop = switchBottom - mSwitchHeight;
break;
}
mSwitchLeft = switchLeft;
mSwitchTop = switchTop;
mSwitchBottom = switchBottom;
mSwitchRight = switchRight;
}
示例12: ReactTextView
public ReactTextView(Context context) {
super(context);
mDefaultGravityHorizontal =
getGravity() & (Gravity.HORIZONTAL_GRAVITY_MASK | Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK);
mDefaultGravityVertical = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
}
示例13: drawDiscreteIndicator
/**
* Draws discrete indicator of this SeekBarWidget at its current position updated by
* {@link #updateDiscreteIndicatorPosition(int, int)} according to the current progress.
*
* @param canvas Canvas on which to draw discrete indicator's drawable.
*/
private void drawDiscreteIndicator(Canvas canvas) {
if (mDiscreteIndicatorHeight == 0) {
return;
}
// todo: draw according to LTR/RTL layout direction.
mDiscreteIndicator.draw(canvas);
// Draw current progress over indicator's graphics.
final Rect indicatorBounds = mDiscreteIndicator.getBounds();
final Paint textPaint = DISCRETE_INDICATOR_TEXT_INFO.paint;
textPaint.getTextBounds("0", 0, 1, mRect);
final float textSize = mRect.height();
final Rect textPadding = DISCRETE_INDICATOR_TEXT_INFO.padding;
final int absoluteTextGravity = WidgetGravity.getAbsoluteGravity(
DISCRETE_INDICATOR_TEXT_INFO.gravity,
ViewCompat.getLayoutDirection(this)
);
final float textX, textY;
// Resolve horizontal text position according to the requested gravity.
switch (absoluteTextGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
textPaint.setTextAlign(Paint.Align.CENTER);
textX = indicatorBounds.centerX();
break;
case Gravity.RIGHT:
textPaint.setTextAlign(Paint.Align.RIGHT);
textX = indicatorBounds.right - textPadding.right;
break;
case Gravity.LEFT:
default:
textPaint.setTextAlign(Paint.Align.LEFT);
textX = indicatorBounds.left + textPadding.left;
break;
}
// Resolve vertical text position according to the requested gravity.
switch (absoluteTextGravity & Gravity.VERTICAL_GRAVITY_MASK) {
case Gravity.CENTER_VERTICAL:
textY = indicatorBounds.centerY() + textSize / 2f;
break;
case Gravity.BOTTOM:
textY = indicatorBounds.bottom - textPadding.bottom;
break;
case Gravity.TOP:
default:
textY = indicatorBounds.top + textSize + textPadding.top;
break;
}
canvas.drawText(Integer.toString(getProgress()), textX, textY, textPaint);
}
示例14: makeCubicGradientScrimDrawable
/**
* This helper method creates a 'nice' scrim or background protection for layering text over
* an image. This non-linear scrim is less noticable than a linear or constant one.
*
* Borrowed from github.com/romannurik/muzei
*
* 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) {
numStops = Math.max(numStops, 2);
PaintDrawable paintDrawable = new PaintDrawable();
paintDrawable.setShape(new RectShape());
final int[] stopColors = new int[numStops];
int alpha = Color.alpha(baseColor);
for (int i = 0; i < numStops; i++) {
double x = i * 1f / (numStops - 1);
double opacity = Math.max(0, Math.min(1, Math.pow(x, 3)));
stopColors[i] = (baseColor & 0x00ffffff) | ((int) (alpha * opacity) << 24);
}
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) {
LinearGradient linearGradient = new LinearGradient(
width * x0,
height * y0,
width * x1,
height * y1,
stopColors, null,
Shader.TileMode.CLAMP);
return linearGradient;
}
});
return paintDrawable;
}
示例15: 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();
}