本文整理匯總了Java中android.graphics.drawable.Drawable.setBounds方法的典型用法代碼示例。如果您正苦於以下問題:Java Drawable.setBounds方法的具體用法?Java Drawable.setBounds怎麽用?Java Drawable.setBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.Drawable
的用法示例。
在下文中一共展示了Drawable.setBounds方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawable2Bitmap
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static Bitmap drawable2Bitmap(final Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
Bitmap bitmap;
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1,
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
示例2: drawPageHints
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private void drawPageHints(Canvas canvas) {
if (mShowPageHints) {
Workspace workspace = mLauncher.getWorkspace();
int width = getMeasuredWidth();
int page = workspace.getNextPage();
CellLayout leftPage = (CellLayout) workspace.getChildAt(mIsRtl ? page + 1 : page - 1);
CellLayout rightPage = (CellLayout) workspace.getChildAt(mIsRtl ? page - 1 : page + 1);
if (leftPage != null && leftPage.isDragTarget()) {
Drawable left = mInScrollArea && leftPage.getIsDragOverlapping() ?
mLeftHoverDrawableActive : mLeftHoverDrawable;
left.setBounds(0, mScrollChildPosition.top,
left.getIntrinsicWidth(), mScrollChildPosition.bottom);
left.draw(canvas);
}
if (rightPage != null && rightPage.isDragTarget()) {
Drawable right = mInScrollArea && rightPage.getIsDragOverlapping() ?
mRightHoverDrawableActive : mRightHoverDrawable;
right.setBounds(width - right.getIntrinsicWidth(),
mScrollChildPosition.top, width, mScrollChildPosition.bottom);
right.draw(canvas);
}
}
}
示例3: drawOverscrollFooter
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void drawOverscrollFooter(Canvas canvas, Drawable drawable, Rect bounds) {
final int height = drawable.getMinimumHeight();
canvas.save();
canvas.clipRect(bounds);
final int span = bounds.bottom - bounds.top;
if (span < height) {
bounds.bottom = bounds.top + height;
}
drawable.setBounds(bounds);
drawable.draw(canvas);
canvas.restore();
}
示例4: drawable2Bitmap
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable == null) {
return null;
}
// 取 drawable 的長寬
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
// 取 drawable 的顏色格式
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
// 建立對應 bitmap
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
// 建立對應 bitmap 的畫布
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
// 把 drawable 內容畫到畫布中
drawable.draw(canvas);
return bitmap;
}
示例5: drawableToBitmap1
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public static Bitmap drawableToBitmap1(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
Bitmap bitmap;
int width = Math.max(drawable.getIntrinsicWidth(), 2);
int height = Math.max(drawable.getIntrinsicHeight(), 2);
try {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
} catch (IllegalArgumentException e) {
MyLg.e(TAG, "Error " + e.getMessage());
e.printStackTrace();
bitmap = null;
}
return bitmap;
}
示例6: setRightImage
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* 設置右側圖片
* @param textView
* @param resId
* @param padding
*/
public static void setRightImage(TextView textView, int resId, float padding) {
if (textView != null) {
Drawable drawable = textView.getContext().getResources().getDrawable(resId);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
textView.setCompoundDrawables(null, null, drawable, null);
}
}
示例7: getResizedDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Nullable
private static Drawable getResizedDrawable(@NonNull Context context, @Nullable Drawable drawable,
int color, boolean tint) {
try {
if (drawable == null) {
LogUtil.d("drawable: null");
return null;
}
if (tint) {
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
drawable.mutate();
}
int size = context.getResources().getDimensionPixelSize(R.dimen.cafebar_icon_size);
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return new BitmapDrawable(context.getResources(),
Bitmap.createScaledBitmap(bitmap, size, size, true));
} catch (Exception | OutOfMemoryError e) {
LogUtil.e(Log.getStackTraceString(e));
return null;
}
}
示例8: fetchDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Get the Drawable from URL
*/
public Drawable fetchDrawable(Resources res, String urlString) {
try {
InputStream is = fetch(urlString);
Drawable drawable = new BitmapDrawable(res, is);
scale = getScale(drawable.getIntrinsicWidth());
drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * scale), (int) (drawable.getIntrinsicHeight() * scale));
return drawable;
} catch (Exception e) {
return null;
}
}
示例9: setIcon
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public void setIcon(Drawable icon) {
this.icon = icon;
if (icon != null) {
if (getMeasuredHeight() <= 0)
measure(0, 0);
int iconWidth = (int) (getMeasuredHeight() * 0.72);
icon.setBounds(0, 0, iconWidth, iconWidth);
}
if (!isChecked())
setChecked(false);
}
示例10: onBindViewHolder
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void onBindViewHolder(final RecyclerView.ViewHolder holder, Cursor cursor) {
if (holder instanceof CaptureViewHolder) {
CaptureViewHolder captureViewHolder = (CaptureViewHolder) holder;
Drawable[] drawables = captureViewHolder.mHint.getCompoundDrawables();
TypedArray ta = holder.itemView.getContext().getTheme().obtainStyledAttributes(
new int[]{R.attr.capture_textColor});
int color = ta.getColor(0, 0);
ta.recycle();
for (int i = 0; i < drawables.length; i++) {
Drawable drawable = drawables[i];
if (drawable != null) {
final Drawable.ConstantState state = drawable.getConstantState();
if (state == null) {
continue;
}
Drawable newDrawable = state.newDrawable().mutate();
newDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
newDrawable.setBounds(drawable.getBounds());
drawables[i] = newDrawable;
}
}
captureViewHolder.mHint.setCompoundDrawables(drawables[0], drawables[1], drawables[2], drawables[3]);
} else if (holder instanceof MediaViewHolder) {
MediaViewHolder mediaViewHolder = (MediaViewHolder) holder;
final Item item = Item.valueOf(cursor);
mediaViewHolder.mMediaGrid.preBindMedia(new MediaGrid.PreBindInfo(
getImageResize(mediaViewHolder.mMediaGrid.getContext()),
mPlaceholder,
mSelectionSpec.countable,
holder
));
mediaViewHolder.mMediaGrid.bindMedia(item);
mediaViewHolder.mMediaGrid.setOnMediaGridClickListener(this);
setCheckStatus(item, mediaViewHolder.mMediaGrid);
}
}
示例11: generateIconBitmaps
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Bitmap[] generateIconBitmaps(Drawable drawable) {
if (drawable == null)
return null;
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return generateIconBitmaps(Bitmap.createScaledBitmap(bitmap, iconSize, iconSize, false));
}
示例12: drawableToBitmap
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* drawable轉bitmap
*
* @param drawable
* @return
*/
private Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
return bitmapDrawable.getBitmap();
}
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
Bitmap bitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
drawable.draw(canvas);
return bitmap;
}
示例13: drawIcon
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected static void drawIcon(@Nonnull final Canvas canvas,@Nonnull final Drawable icon,
final int x, final int y, final int width, final int height) {
canvas.translate(x, y);
icon.setBounds(0, 0, width, height);
icon.draw(canvas);
canvas.translate(-x, -y);
}
示例14: getBitmapFromDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Bitmap getBitmapFromDrawable(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
try {
Bitmap bitmap;
if (drawable instanceof ColorDrawable) {
bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例15: setDrawleft
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public void setDrawleft(TextView view, int id) {
if (!isAdded()) return;
Drawable drawable_n = getResources().getDrawable(id);
drawable_n.setBounds(0, 0, drawable_n.getMinimumWidth(), drawable_n.getMinimumHeight()); //此為必須寫的
view.setCompoundDrawables(drawable_n, null, null, null);
}