當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。