本文整理了Java中android.graphics.drawable.Drawable.copyBounds()
方法的一些代码示例,展示了Drawable.copyBounds()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Drawable.copyBounds()
方法的具体详情如下:
包路径:android.graphics.drawable.Drawable
类名称:Drawable
方法名:copyBounds
暂无
代码示例来源:origin: andkulikov/Transitions-Everywhere
@Override
@NonNull
public PointF get(@NonNull Drawable object) {
object.copyBounds(mBounds);
return new PointF(mBounds.left, mBounds.top);
}
};
代码示例来源:origin: PhilJay/MPAndroidChart
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);
}
代码示例来源:origin: PhilJay/MPAndroidChart
mDrawable.copyBounds(mDrawableBoundsCache);
mDrawable.setBounds(
mDrawableBoundsCache.left,
代码示例来源:origin: andkulikov/Transitions-Everywhere
@Override
public void set(@NonNull Drawable object, @NonNull PointF value) {
object.copyBounds(mBounds);
mBounds.offsetTo(Math.round(value.x), Math.round(value.y));
object.setBounds(mBounds);
}
代码示例来源:origin: lyft/scissors
public static Bitmap asBitmap(Drawable drawable, int minWidth, int minHeight) {
final Rect tmpRect = new Rect();
drawable.copyBounds(tmpRect);
if (tmpRect.isEmpty()) {
tmpRect.set(0, 0, Math.max(minWidth, drawable.getIntrinsicWidth()), Math.max(minHeight, drawable.getIntrinsicHeight()));
drawable.setBounds(tmpRect);
}
Bitmap bitmap = Bitmap.createBitmap(tmpRect.width(), tmpRect.height(), Bitmap.Config.ARGB_8888);
drawable.draw(new Canvas(bitmap));
return bitmap;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void copyBoundsWithPassedRect() {
Drawable drawable = ShadowDrawable.createFromStream(new ByteArrayInputStream(new byte[0]), "my_source");
drawable.setBounds(1, 2, 3, 4);
Rect r = new Rect();
drawable.copyBounds(r);
assertThat(r.left).isEqualTo(1);
assertThat(r.top).isEqualTo(2);
assertThat(r.right).isEqualTo(3);
assertThat(r.bottom).isEqualTo(4);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void copyBoundsToReturnedRect() {
Drawable drawable = ShadowDrawable.createFromStream(new ByteArrayInputStream(new byte[0]), "my_source");
drawable.setBounds(1, 2, 3, 4);
Rect r = drawable.copyBounds();
assertThat(r.left).isEqualTo(1);
assertThat(r.top).isEqualTo(2);
assertThat(r.right).isEqualTo(3);
assertThat(r.bottom).isEqualTo(4);
}
代码示例来源:origin: listenzz/AndroidNavigation
public void setTabBar(Drawable drawable) {
this.mTabBar = drawable;
if (drawable != null) {
mTabBarOriginBounds = drawable.copyBounds();
}
}
代码示例来源:origin: WeAreFairphone/FP2-Launcher
private static void renderDrawableToBitmap(
Drawable d, Bitmap bitmap, int x, int y, int w, int h) {
if (bitmap != null) {
Canvas c = new Canvas(bitmap);
Rect oldBounds = d.copyBounds();
d.setBounds(x, y, x + w, y + h);
d.draw(c);
d.setBounds(oldBounds); // Restore the bounds
c.setBitmap(null);
}
}
代码示例来源:origin: enricocid/LaunchEnr
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;
}
代码示例来源:origin: xiaolongonly/Ticket-Analysis
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);
}
代码示例来源:origin: com.github.PhilJay/MPAndroidChart
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);
}
代码示例来源:origin: WenWangAndroid/ChartManager
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);
}
代码示例来源:origin: WallaceXiao/StockChart-MPAndroidChart
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);
}
代码示例来源:origin: fookwood/Launcher3
private 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;
}
代码示例来源:origin: klinker24/Android-Blur-Launcher
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;
}
代码示例来源:origin: klinker24/launcher3
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;
}
代码示例来源:origin: WeAreFairphone/FP2-Launcher
private 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;
}
代码示例来源:origin: stackoverflow.com
public static void centerImageAndTextInButton(Button button) {
Rect textBounds = new Rect();
//Get text bounds
CharSequence text = button.getText();
if (text != null && text.length() > 0) {
TextPaint textPaint = button.getPaint();
textPaint.getTextBounds(text.toString(), 0, text.length(), textBounds);
}
//Set left drawable bounds
Drawable leftDrawable = button.getCompoundDrawables()[0];
if (leftDrawable != null) {
Rect leftBounds = leftDrawable.copyBounds();
int width = button.getWidth() - (button.getPaddingLeft() + button.getPaddingRight());
int leftOffset = (width - (textBounds.width() + leftBounds.width()) - button.getCompoundDrawablePadding()) / 2 - button.getCompoundDrawablePadding();
leftBounds.offset(leftOffset, 0);
leftDrawable.setBounds(leftBounds);
}
}
代码示例来源:origin: stackoverflow.com
public static void centerImageAndTextInButton(Button button) {
Rect textBounds = new Rect();
//Get text bounds
CharSequence text = button.getText();
if (text != null && text.length() > 0) {
TextPaint textPaint = button.getPaint();
textPaint.getTextBounds(text.toString(), 0, text.length(), textBounds);
}
//Set left drawable bounds
Drawable leftDrawable = button.getCompoundDrawables()[0];
if (leftDrawable != null) {
Rect leftBounds = leftDrawable.copyBounds();
int width = button.getWidth() - (button.getPaddingLeft() + button.getPaddingRight());
int leftOffset = (width - (textBounds.width() + leftBounds.width()) - button.getCompoundDrawablePadding()) / 2 - button.getCompoundDrawablePadding();
leftBounds.offset(leftOffset, 0);
leftDrawable.setBounds(leftBounds);
}
}
内容来源于网络,如有侵权,请联系作者删除!