本文整理匯總了Java中android.graphics.drawable.Drawable.copyBounds方法的典型用法代碼示例。如果您正苦於以下問題:Java Drawable.copyBounds方法的具體用法?Java Drawable.copyBounds怎麽用?Java Drawable.copyBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.Drawable
的用法示例。
在下文中一共展示了Drawable.copyBounds方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawImage
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public static void drawImage(Canvas canvas,
Drawable drawable,
int x, int y,
int width, int height) {
MPPointF drawOffset = MPPointF.getInstance();
drawOffset.x = x - (width / 2);
drawOffset.y = y - (height / 2);
drawable.copyBounds(mDrawableBoundsCache);
drawable.setBounds(
mDrawableBoundsCache.left,
mDrawableBoundsCache.top,
mDrawableBoundsCache.left + width,
mDrawableBoundsCache.top + width);
int saveId = canvas.save();
// translate to the correct position and draw
canvas.translate(drawOffset.x, drawOffset.y);
drawable.draw(canvas);
canvas.restoreToCount(saveId);
}
示例2: getDrawableBounds
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected static Rect getDrawableBounds(Drawable d) {
Rect bounds = new Rect();
d.copyBounds(bounds);
if (bounds.width() == 0 || bounds.height() == 0) {
bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
} else {
bounds.offsetTo(0, 0);
}
return bounds;
}
示例3: Bouncer
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public Bouncer(
final Drawable drawable,
final int speedX,
final int speedY) {
this.drawable = drawable;
this.bounds = drawable.copyBounds();
this.speedX = speedX;
this.speedY = speedY;
}
示例4: getDrawableBounds
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected static Rect getDrawableBounds(Drawable d) {
Rect bounds = new Rect();
d.copyBounds(bounds);
if (bounds.width() == 0 || bounds.height() == 0) {
bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
} else {
bounds.offsetTo(0, 0);
}
if (d instanceof PreloadIconDrawable) {
int inset = -((PreloadIconDrawable) d).getOutset();
bounds.inset(inset, inset);
}
return bounds;
}
示例5: onDraw
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected void onDraw(Canvas canvas) {
int saveCount;
Layout switchText;
super.onDraw(canvas);
Rect padding = this.mTempRect;
Drawable trackDrawable = this.mTrackDrawable;
if (trackDrawable != null) {
trackDrawable.getPadding(padding);
} else {
padding.setEmpty();
}
int switchTop = this.mSwitchTop;
int switchInnerTop = switchTop + padding.top;
int switchInnerBottom = this.mSwitchBottom - padding.bottom;
Drawable thumbDrawable = this.mThumbDrawable;
if (trackDrawable != null) {
if (!this.mSplitTrack || thumbDrawable == null) {
trackDrawable.draw(canvas);
} else {
Rect insets = DrawableUtils.getOpticalBounds(thumbDrawable);
thumbDrawable.copyBounds(padding);
padding.left += insets.left;
padding.right -= insets.right;
saveCount = canvas.save();
canvas.clipRect(padding, Op.DIFFERENCE);
trackDrawable.draw(canvas);
canvas.restoreToCount(saveCount);
}
}
saveCount = canvas.save();
if (thumbDrawable != null) {
thumbDrawable.draw(canvas);
}
if (getTargetCheckedState()) {
switchText = this.mOnLayout;
} else {
switchText = this.mOffLayout;
}
if (switchText != null) {
int cX;
int[] drawableState = getDrawableState();
if (this.mTextColors != null) {
this.mTextPaint.setColor(this.mTextColors.getColorForState(drawableState, 0));
}
this.mTextPaint.drawableState = drawableState;
if (thumbDrawable != null) {
Rect bounds = thumbDrawable.getBounds();
cX = bounds.left + bounds.right;
} else {
cX = getWidth();
}
canvas.translate((float) ((cX / 2) - (switchText.getWidth() / 2)), (float) (((switchInnerTop + switchInnerBottom) / 2) - (switchText.getHeight() / 2)));
switchText.draw(canvas);
}
canvas.restoreToCount(saveCount);
}