当前位置: 首页>>代码示例>>Java>>正文


Java Gravity.VERTICAL_GRAVITY_MASK属性代码示例

本文整理汇总了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;
}
 
开发者ID:rexyren,项目名称:PageScrollView,代码行数:18,代码来源:BaseViewGroup.java

示例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);
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-android,代码行数:26,代码来源:RadioButtonCenter.java

示例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);
  }
}
 
开发者ID:commonsguy,项目名称:cwac-crossport,代码行数:20,代码来源:TextInputLayout.java

示例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;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:47,代码来源:HoloCircularProgressBar.java

示例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;
    }
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:11,代码来源:AutoLinearLayout.java

示例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;
    }
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:10,代码来源:VerticalTextView.java

示例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;
}
 
开发者ID:Onelio,项目名称:ConnectU,代码行数:9,代码来源:VerticalTextView.java

示例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;
        }
    }
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:41,代码来源:QMUIWindowInsetHelper.java

示例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);
}
 
开发者ID:tylersuehr7,项目名称:empty-state-recyclerview,代码行数:49,代码来源:ImageStateDisplay.java

示例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();
}
 
开发者ID:tylersuehr7,项目名称:empty-state-recyclerview,代码行数:45,代码来源:TextStateDisplay.java

示例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;
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:55,代码来源:Switch.java

示例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;
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:6,代码来源:ReactTextView.java

示例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);
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:56,代码来源:SeekBarWidget.java

示例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;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:54,代码来源:UIUtils.java

示例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();
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:78,代码来源:PhotoViewer.java


注:本文中的android.view.Gravity.VERTICAL_GRAVITY_MASK属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。