本文整理匯總了Java中android.view.Gravity.apply方法的典型用法代碼示例。如果您正苦於以下問題:Java Gravity.apply方法的具體用法?Java Gravity.apply怎麽用?Java Gravity.apply使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.Gravity
的用法示例。
在下文中一共展示了Gravity.apply方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateBounds
import android.view.Gravity; //導入方法依賴的package包/類
/**
* 更新bounds
*
* @param view
* @param drawable
*/
private void updateBounds(View view, Drawable drawable) {
if (drawable != null) {
final Rect selfBounds = mSelfBounds;
final Rect overlayBounds = mOverlayBounds;
final int w = view.getRight() - view.getLeft();
final int h = view.getBottom() - view.getTop();
if (mForegroundInPadding) {
selfBounds.set(0, 0, w, h);
} else {
selfBounds.set(view.getPaddingLeft(), view.getPaddingTop(), w - view.getPaddingRight(), h - view.getPaddingBottom());
}
Gravity.apply(mForegroundGravity, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), selfBounds, overlayBounds);
drawable.setBounds(overlayBounds);
}
}
示例2: updateDstRect
import android.view.Gravity; //導入方法依賴的package包/類
private void updateDstRect() {
if (dirtyDraw) {
final Rect bounds = getBounds();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
final int layoutDirection = getLayoutDirection();
Gravity.apply(Gravity.FILL, bitmap.getWidth(), bitmap.getHeight(),
bounds, mDstRect, layoutDirection);
} else {
Gravity.apply(Gravity.FILL, bitmap.getWidth(), bitmap.getHeight(),
bounds, mDstRect);
}
}
configureRadiusRect();
dirtyDraw = false;
}
示例3: draw
import android.view.Gravity; //導入方法依賴的package包/類
public void draw(@NonNull Canvas canvas) {
super.draw(canvas);
if (this.mForeground != null) {
Drawable foreground = this.mForeground;
if (this.mForegroundBoundsChanged) {
this.mForegroundBoundsChanged = false;
Rect selfBounds = this.mSelfBounds;
Rect overlayBounds = this.mOverlayBounds;
int w = getRight() - getLeft();
int h = getBottom() - getTop();
if (this.mForegroundInPadding) {
selfBounds.set(0, 0, w, h);
} else {
selfBounds.set(getPaddingLeft(), getPaddingTop(), w - getPaddingRight(), h - getPaddingBottom());
}
Gravity.apply(this.mForegroundGravity, foreground.getIntrinsicWidth(), foreground.getIntrinsicHeight(), selfBounds, overlayBounds);
foreground.setBounds(overlayBounds);
}
foreground.draw(canvas);
}
}
示例4: onLayout
import android.view.Gravity; //導入方法依賴的package包/類
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
final int layoutWidth = right - left;
final int layoutHeight = bottom - top;
if (mIllustration != null) {
int intrinsicWidth = mIllustration.getIntrinsicWidth();
int intrinsicHeight = mIllustration.getIntrinsicHeight();
mViewBounds.set(0, 0, layoutWidth, layoutHeight);
if (mAspectRatio != 0f) {
mScale = layoutWidth / (float) intrinsicWidth;
intrinsicWidth = layoutWidth;
intrinsicHeight = (int) (intrinsicHeight * mScale);
}
Gravity.apply(Gravity.FILL_HORIZONTAL | Gravity.TOP, intrinsicWidth,
intrinsicHeight, mViewBounds, mIllustrationBounds);
mIllustration.setBounds(mIllustrationBounds);
}
if (mBackground != null) {
// Scale the background bounds by the same scale to compensate for the scale done to the
// canvas in onDraw.
mBackground.setBounds(0, 0, (int) Math.ceil(layoutWidth / mScale),
(int) Math.ceil((layoutHeight - mIllustrationBounds.height()) / mScale));
}
super.onLayout(changed, left, top, right, bottom);
}
示例5: draw
import android.view.Gravity; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
if (isRecycled) {
return;
}
if (applyGravity) {
Gravity.apply(GifState.GRAVITY, getIntrinsicWidth(), getIntrinsicHeight(), getBounds(),
getDestRect());
applyGravity = false;
}
Bitmap currentFrame = state.frameLoader.getCurrentFrame();
canvas.drawBitmap(currentFrame, null, getDestRect(), getPaint());
}
示例6: draw
import android.view.Gravity; //導入方法依賴的package包/類
@Override
public void draw(@NonNull Canvas canvas) {
if (isRecycled) {
return;
}
if (applyGravity) {
Gravity.apply(GRAVITY, getIntrinsicWidth(), getIntrinsicHeight(), getBounds(), getDestRect());
applyGravity = false;
}
Bitmap currentFrame = state.frameLoader.getCurrentFrame();
canvas.drawBitmap(currentFrame, null, getDestRect(), getPaint());
}
示例7: layoutBadge
import android.view.Gravity; //導入方法依賴的package包/類
private void layoutBadge() {
Rect badgeBounds = badge.getBounds();
Gravity.apply(badgeGravity,
badge.getIntrinsicWidth(),
badge.getIntrinsicHeight(),
new Rect(0, 0, getWidth(), getHeight()),
badgePadding,
badgePadding,
badgeBounds);
badge.setBounds(badgeBounds);
badgeBoundsSet = true;
}
示例8: apply
import android.view.Gravity; //導入方法依賴的package包/類
public void apply(int gravity, int w, int h, Rect container, Rect outRect, int layoutDirection) {
Gravity.apply(gravity, w, h, container, outRect);
}
示例9: draw
import android.view.Gravity; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
if (mForeground != null) {
final Drawable foreground = mForeground;
if (mForegroundBoundsChanged) {
mForegroundBoundsChanged = false;
final Rect selfBounds = mSelfBounds;
final Rect overlayBounds = mOverlayBounds;
final int w = getRight() - getLeft();
final int h = getBottom() - getTop();
if (mForegroundInPadding) {
selfBounds.set(0, 0, w, h);
} else {
selfBounds.set(getPaddingLeft(), getPaddingTop(),
w - getPaddingRight(), h - getPaddingBottom());
}
Gravity.apply(mForegroundGravity, foreground.getIntrinsicWidth(),
foreground.getIntrinsicHeight(), selfBounds, overlayBounds);
foreground.setBounds(overlayBounds);
}
foreground.draw(canvas);
}
}
示例10: onLayout
import android.view.Gravity; //導入方法依賴的package包/類
/**
* Position all children within this layout.
*/
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
final int count = getChildCount();
int leftPos = getPaddingLeft();
final int parentTop = getPaddingTop();
final int parentBottom = bottom - top - getPaddingBottom();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
final int width = child.getMeasuredWidth();
final int height = child.getMeasuredHeight();
mTmpContainerRect.left = leftPos;
mTmpContainerRect.right = leftPos;
leftPos = mTmpContainerRect.right;
mTmpContainerRect.top = parentTop;
mTmpContainerRect.bottom = parentBottom;
Gravity.apply(Gravity.TOP | Gravity.LEFT, width, height,
mTmpContainerRect, mTmpChildRect);
child.layout(mTmpChildRect.left, mTmpChildRect.top,
mTmpChildRect.right, mTmpChildRect.bottom);
}
}
}
示例11: onLayout
import android.view.Gravity; //導入方法依賴的package包/類
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
final int count = getChildCount();
// These are the far left and right edges in which we are performing
// layout.
int leftPos = getPaddingLeft();
int rightPos = right - left - getPaddingRight();
// This is the middle region inside of the gutter.
final int middleLeft = leftPos + mLeftWidth;
final int middleRight = rightPos - mRightWidth;
// These are the top and bottom edges in which we are performing layout.
final int parentTop = getPaddingTop();
final int parentBottom = bottom - top - getPaddingBottom();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int width = child.getMeasuredWidth();
final int height = child.getMeasuredHeight();
// Compute the frame in which we are placing this child.
if (lp.position == LayoutParams.POSITION_LEFT) {
mTmpContainerRect.left = leftPos + lp.leftMargin;
mTmpContainerRect.right = leftPos + width + lp.rightMargin;
leftPos = mTmpContainerRect.right;
} else if (lp.position == LayoutParams.POSITION_RIGHT) {
mTmpContainerRect.right = rightPos - lp.rightMargin;
mTmpContainerRect.left = rightPos - width - lp.leftMargin;
rightPos = mTmpContainerRect.left;
} else {
mTmpContainerRect.left = middleLeft + lp.leftMargin;
mTmpContainerRect.right = middleRight - lp.rightMargin;
}
mTmpContainerRect.top = parentTop + lp.topMargin;
mTmpContainerRect.bottom = parentBottom - lp.bottomMargin;
// Use the child's gravity and size to determine its final
// frame within its container.
Gravity.apply(lp.gravity, width, height, mTmpContainerRect, mTmpChildRect);
// Place the child.
child.layout(mTmpChildRect.left + xPos, mTmpChildRect.top + yPos, mTmpChildRect.right + xPos,
mTmpChildRect.bottom + yPos);
}
}
}
示例12: apply
import android.view.Gravity; //導入方法依賴的package包/類
public static void apply(int gravity, int w, int h, Rect container, Rect outRect, int layoutDirection) {
Gravity.apply(gravity, w, h, container, outRect, layoutDirection);
}
示例13: gravityCompatApply
import android.view.Gravity; //導入方法依賴的package包/類
void gravityCompatApply(int gravity, int bitmapWidth, int bitmapHeight, Rect bounds, Rect outRect) {
Gravity.apply(gravity, bitmapWidth, bitmapHeight, bounds, outRect, 0);
}