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


Java Gravity.getAbsoluteGravity方法代码示例

本文整理汇总了Java中android.view.Gravity.getAbsoluteGravity方法的典型用法代码示例。如果您正苦于以下问题:Java Gravity.getAbsoluteGravity方法的具体用法?Java Gravity.getAbsoluteGravity怎么用?Java Gravity.getAbsoluteGravity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.Gravity的用法示例。


在下文中一共展示了Gravity.getAbsoluteGravity方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setTextGravity

import android.view.Gravity; //导入方法依赖的package包/类
/**
 * Sets the overall alignment for the text (supports all gravity variations
 * except for RIGHT and END).
 * @param gravity Text gravity
 */
public void setTextGravity(int gravity) {
    // Let's adjust paint alignment to fit horizontal gravity (END not supported)
    final int horizontalGravity = Gravity.getAbsoluteGravity(gravity,
            ViewCompat.LAYOUT_DIRECTION_LTR)&Gravity.HORIZONTAL_GRAVITY_MASK;
    switch (horizontalGravity) {
        case GravityCompat.START:
            this.titlePaint.setTextAlign(Paint.Align.LEFT);
            this.subtitlePaint.setTextAlign(Paint.Align.LEFT);
            break;
        case Gravity.CENTER_HORIZONTAL:
            this.titlePaint.setTextAlign(Paint.Align.CENTER);
            this.subtitlePaint.setTextAlign(Paint.Align.CENTER);
            break;
    }
    this.textGravity = gravity;
    // No invalidation needed
}
 
开发者ID:tylersuehr7,项目名称:empty-state-recyclerview,代码行数:23,代码来源:TextStateDisplay.java

示例2: setGravity

import android.view.Gravity; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:gslovemy,项目名称:ToastCompat,代码行数:33,代码来源:CustomToast.java

示例3: applyGravity

import android.view.Gravity; //导入方法依赖的package包/类
/**
 * apply the gravity for window params.
 *
 * @param expectGravity the expect gravity
 * @param applyWlp      the window layout params.
 */
private static void applyGravity(Context context,int expectGravity, WindowManager.LayoutParams applyWlp) {
    if (Build.VERSION.SDK_INT >= 17) {
        final Configuration configuration = context.getResources().getConfiguration();
        final int gravity = Gravity.getAbsoluteGravity(expectGravity, configuration.getLayoutDirection());
        applyWlp.gravity = gravity;
        if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
            applyWlp.horizontalWeight = 1.0f;
        }
        if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
            applyWlp.verticalWeight = 1.0f;
        }
    } else {
        applyWlp.gravity = expectGravity;
    }
}
 
开发者ID:LightSun,项目名称:android-util2,代码行数:22,代码来源:BaseWindow.java

示例4: computeInsets

import android.view.Gravity; //导入方法依赖的package包/类
/**
 * 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,代码行数:48,代码来源:HoloCircularProgressBar.java

示例5: SlideInItemAnimator

import android.view.Gravity; //导入方法依赖的package包/类
public SlideInItemAnimator(int slideFromEdge, int layoutDirection) {
    this.slideFromEdge = Gravity.getAbsoluteGravity(slideFromEdge, layoutDirection);
    setAddDuration(160L);
}
 
开发者ID:reidzeibel,项目名称:AnimatedListAdapter,代码行数:5,代码来源:SlideInItemAnimator.java

示例6: onDrawState

import android.view.Gravity; //导入方法依赖的package包/类
@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,代码行数:50,代码来源:ImageStateDisplay.java

示例7: onDrawState

import android.view.Gravity; //导入方法依赖的package包/类
@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,代码行数:46,代码来源:TextStateDisplay.java

示例8: makeAndAddView

import android.view.Gravity; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void makeAndAddView(View child, int index) {

    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) child.getLayoutParams();
    addViewInLayout(child, 0, lp, true);

    final boolean needToMeasure = child.isLayoutRequested();
    if (needToMeasure) {
        int childWidthSpec = getChildMeasureSpec(getWidthMeasureSpec(),
                getPaddingLeft() + getPaddingRight() + lp.leftMargin + lp.rightMargin,
                lp.width);
        int childHeightSpec = getChildMeasureSpec(getHeightMeasureSpec(),
                getPaddingTop() + getPaddingBottom() + lp.topMargin + lp.bottomMargin,
                lp.height);
        child.measure(childWidthSpec, childHeightSpec);
    } else {
        cleanupLayoutState(child);
    }

    int w = child.getMeasuredWidth();
    int h = child.getMeasuredHeight();

    int gravity = lp.gravity;
    if (gravity == -1) {
        gravity = Gravity.TOP | Gravity.START;
    }

    int layoutDirection = 0;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN)
        layoutDirection = getLayoutDirection();
    final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
    final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

    int childLeft;
    int childTop;
    switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            childLeft = (getWidth() + getPaddingLeft() - getPaddingRight()  - w) / 2 +
                    lp.leftMargin - lp.rightMargin;
            break;
        case Gravity.END:
            childLeft = getWidth() + getPaddingRight() - w - lp.rightMargin;
            break;
        case Gravity.START:
        default:
            childLeft = getPaddingLeft() + lp.leftMargin;
            break;
    }
    switch (verticalGravity) {
        case Gravity.CENTER_VERTICAL:
            childTop = (getHeight() + getPaddingTop() - getPaddingBottom()  - h) / 2 +
                    lp.topMargin - lp.bottomMargin;
            break;
        case Gravity.BOTTOM:
            childTop = getHeight() - getPaddingBottom() - h - lp.bottomMargin;
            break;
        case Gravity.TOP:
        default:
            childTop = getPaddingTop() + lp.topMargin;
            break;
    }
    child.layout(childLeft, childTop, childLeft + w, childTop + h);
    // 缩放层叠效果
    adjustChildView(child, index);
}
 
开发者ID:marven88cn,项目名称:SwipeCard-,代码行数:66,代码来源:SwipeFlingAdapterView.java

示例9: getAbsoluteGravity

import android.view.Gravity; //导入方法依赖的package包/类
/**
 * Compatibility version of {@link Gravity#getAbsoluteGravity(int, int)}.
 */
@SuppressWarnings("NewApi")
public static int getAbsoluteGravity(int gravity, int layoutDirection) {
	return RTL_SUPPORT ? Gravity.getAbsoluteGravity(gravity, layoutDirection) : gravity;
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:8,代码来源:WidgetGravity.java

示例10: getAbsoluteGravity

import android.view.Gravity; //导入方法依赖的package包/类
public static int getAbsoluteGravity(int gravity, int layoutDirection) {
    return Gravity.getAbsoluteGravity(gravity, layoutDirection);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:4,代码来源:GravityCompatJellybeanMr1.java

示例11: getAbsoluteOrigin

import android.view.Gravity; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static int getAbsoluteOrigin(int origin, int layoutDirection) {
  return Gravity.getAbsoluteGravity(origin, layoutDirection);
}
 
开发者ID:xzg8023,项目名称:ArcLayout-master,代码行数:5,代码来源:ArcOrigin.java


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