本文整理匯總了Java中android.graphics.drawable.Drawable.getMinimumWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java Drawable.getMinimumWidth方法的具體用法?Java Drawable.getMinimumWidth怎麽用?Java Drawable.getMinimumWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.Drawable
的用法示例。
在下文中一共展示了Drawable.getMinimumWidth方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onMeasure
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// 創建一個測量規格
// int measureSpec = MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY);
// 打印一下父容器傳過來的測量規格
// System.out.println("父容器傳過來的測量規格");
MeasureSpecUtil.printMeasureSpec(widthMeasureSpec, heightMeasureSpec);
Drawable drawable = getDrawable();
if (drawable != null) {
int picWidth = drawable.getMinimumWidth(); // 獲取圖片的寬
int picHeight = drawable.getMinimumHeight();// 獲取圖片的高
float scale = (float) picHeight / picWidth; // 最終要算什麽樣的值,這個值做為被除數
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = (int) (width * scale);
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// System.out.println("ImageView測量出來的自己的寬高為:" + getMeasuredWidth() + " x " + getMeasuredHeight());
}
示例2: drawOverscrollHeader
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void drawOverscrollHeader(Canvas canvas, Drawable drawable, Rect bounds) {
final int width = drawable.getMinimumWidth();
canvas.save();
canvas.clipRect(bounds);
final int span = bounds.right - bounds.left;
if (span < width) {
bounds.left = bounds.right - width;
}
drawable.setBounds(bounds);
drawable.draw(canvas);
canvas.restore();
}
示例3: drawOverscrollFooter
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void drawOverscrollFooter(Canvas canvas, Drawable drawable, Rect bounds) {
final int width = drawable.getMinimumWidth();
canvas.save();
canvas.clipRect(bounds);
final int span = bounds.right - bounds.left;
if (span < width) {
bounds.right = bounds.left + width;
}
drawable.setBounds(bounds);
drawable.draw(canvas);
canvas.restore();
}
示例4: onMeasure
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Drawable drawable = getDrawable();
if(drawable != null){
int width = drawable.getMinimumWidth();
int height = drawable.getMinimumHeight();
float scale = (float)height/width;
int widthMeasure = MeasureSpec.getSize(widthMeasureSpec);
int heightMeasure = (int)(widthMeasure*scale);
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightMeasure, MeasureSpec.EXACTLY);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
示例5: drawOverscrollHeader
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void drawOverscrollHeader(Canvas canvas, Drawable drawable, Rect bounds) {
int width = drawable.getMinimumWidth();
canvas.save();
canvas.clipRect(bounds);
if (bounds.right - bounds.left < width) {
bounds.left = bounds.right - width;
}
drawable.setBounds(bounds);
drawable.draw(canvas);
canvas.restore();
}
示例6: drawOverscrollFooter
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void drawOverscrollFooter(Canvas canvas, Drawable drawable, Rect bounds) {
int width = drawable.getMinimumWidth();
canvas.save();
canvas.clipRect(bounds);
if (bounds.right - bounds.left < width) {
bounds.right = bounds.left + width;
}
drawable.setBounds(bounds);
drawable.draw(canvas);
canvas.restore();
}
示例7: setHeaderIcon
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private void setHeaderIcon(ContextMenu menu, Drawable icon) {
int width = getHeaderIconWidth();
if (icon.getMinimumWidth() <= width) {
menu.setHeaderIcon(icon);
} else if (icon instanceof BitmapDrawable) {
Bitmap bitmap = Bitmap.createScaledBitmap(((BitmapDrawable) icon).getBitmap(), width, width, false);
menu.setHeaderIcon(new BitmapDrawable(getResources(), bitmap));
}
}
示例8: cropDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Drawable cropDrawable(Drawable icon) {
int width = getPixel(0x20);
if (icon.getMinimumWidth() > width && icon instanceof BitmapDrawable) {
Bitmap bitmap = Bitmap.createScaledBitmap(((BitmapDrawable) icon).getBitmap(), width, width, false);
return new BitmapDrawable(getResources(), bitmap);
}
return icon;
}
示例9: getWidth
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public int getWidth() {
Drawable drawable = _drawable;
if (drawable == null) {
return 0;
}
return drawable.getMinimumWidth();
}
示例10: drawLens
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected void drawLens(Canvas g, Drawable image, final int w, final int h) {
final int iw = image.getMinimumWidth();
drawImage(g, image, w / 2 - iw / 2, 5, iw, h - 5);
}
示例11: createBadgeDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Drawable createBadgeDrawable(Drawable d, int count) {
if (d == null) return null;
NumberFormat f = NumberFormat.getIntegerInstance();
String countStr = count > 99 ? "99+" : f.format(count);
Bitmap b = Utils.drawableToBitmap(d);
b = b.copy(Bitmap.Config.ARGB_8888, true);
Canvas c = new Canvas(b);
Paint p = new Paint();
p.setTextAlign(Paint.Align.CENTER);
p.setColor(Color.WHITE);
p.setAntiAlias(true);
p.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
mResources.getDisplayMetrics()));
Drawable bg = mGbResources.getDrawable(R.drawable.ic_notification_overlay, null);
final int w = b.getWidth();
final int h = b.getHeight();
final Rect r = new Rect();
p.getTextBounds(countStr, 0, countStr.length(), r);
final int tw = r.right - r.left;
final int th = r.bottom - r.top;
bg.getPadding(r);
int dw = r.left + tw + r.right;
if (dw < bg.getMinimumWidth()) {
dw = bg.getMinimumWidth();
}
int x = w-r.right-((dw-r.right-r.left)/2);
int dh = r.top + th + r.bottom;
if (dh < bg.getMinimumHeight()) {
dh = bg.getMinimumHeight();
}
if (dw < dh) dw = dh;
int y = h-r.bottom-((dh-r.top-th-r.bottom)/2);
bg.setBounds(w-dw, h-dh, w, h);
bg.draw(c);
c.drawText(countStr, x, y, p);
return new BitmapDrawable(mResources, b);
}