本文整理了Java中android.graphics.drawable.Drawable.getIntrinsicWidth()
方法的一些代码示例,展示了Drawable.getIntrinsicWidth()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Drawable.getIntrinsicWidth()
方法的具体详情如下:
包路径:android.graphics.drawable.Drawable
类名称:Drawable
方法名:getIntrinsicWidth
暂无
代码示例来源:origin: bumptech/glide
@Override
public int getSize() {
// 4 bytes per pixel for ARGB_8888 Bitmaps is something of a reasonable approximation. If
// there are no intrinsic bounds, we can fall back just to 1.
return Math.max(1, drawable.getIntrinsicWidth() * drawable.getIntrinsicHeight() * 4);
}
代码示例来源:origin: stackoverflow.com
public static Bitmap drawableToBitmap (Drawable drawable) {
Bitmap bitmap = null;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if(bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
} else {
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 bitmap;
}
代码示例来源:origin: JessYanCoding/MVPArms
/**
* 传入图片,将图片按传入比例缩放
*
* @param percent
* @return
*/
public static Drawable getScaleDrawable(float percent, Drawable drawable) {
drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * percent + 0.5f), (int) (drawable.getIntrinsicHeight() * percent + 0.5f));
return drawable;
}
代码示例来源:origin: jdsjlzx/LRecyclerView
public static void drawLeftAlignItem(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) {
final int top = child.getTop() - params.topMargin;
final int bottom = child.getBottom() + params.bottomMargin;
final int left = child.getLeft() - params.leftMargin - drawable.getIntrinsicWidth();
final int right = left + drawable.getIntrinsicWidth();
drawable.setBounds(left, top, right, bottom);
drawable.draw(canvas);
}
代码示例来源:origin: KeepSafe/TapTargetView
void drawTintedTarget() {
final Drawable icon = target.icon;
if (!shouldTintTarget || icon == null) {
tintedTarget = null;
return;
}
if (tintedTarget != null) return;
tintedTarget = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(tintedTarget);
icon.setColorFilter(new PorterDuffColorFilter(
outerCirclePaint.getColor(), PorterDuff.Mode.SRC_ATOP));
icon.draw(canvas);
icon.setColorFilter(null);
}
代码示例来源:origin: stackoverflow.com
public static Bitmap drawableToBitmap (Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable)drawable).getBitmap();
}
int width = drawable.getIntrinsicWidth();
width = width > 0 ? width : 1;
int height = drawable.getIntrinsicHeight();
height = height > 0 ? height : 1;
Bitmap 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);
return bitmap;
}
代码示例来源:origin: bumptech/glide
FixedSizeDrawable(State state, Drawable wrapped) {
this.state = Preconditions.checkNotNull(state);
this.wrapped = Preconditions.checkNotNull(wrapped);
// We will do our own scaling.
wrapped.setBounds(0, 0, wrapped.getIntrinsicWidth(), wrapped.getIntrinsicHeight());
matrix = new Matrix();
wrappedRect = new RectF(0, 0, wrapped.getIntrinsicWidth(), wrapped.getIntrinsicHeight());
bounds = new RectF();
}
代码示例来源:origin: stackoverflow.com
public class ResizableImageView extends ImageView {
public ResizableImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
Drawable d = getDrawable();
if(d!=null){
// ceil not round - avoid thin vertical gaps along the left/right edges
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = (int) Math.ceil((float) width * (float) d.getIntrinsicHeight() / (float) d.getIntrinsicWidth());
setMeasuredDimension(width, height);
}else{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
代码示例来源:origin: jdsjlzx/LRecyclerView
public static void drawRightAlignItem(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) {
final int top = child.getTop() - params.topMargin;
final int bottom = child.getBottom() + params.bottomMargin;
final int left = child.getRight() + params.rightMargin;
final int right = left + drawable.getIntrinsicWidth();
drawable.setBounds(left, top, right, bottom);
drawable.draw(canvas);
}
代码示例来源:origin: Bearded-Hen/Android-Bootstrap
/**
* @return the original Bitmap source that will be drawn as a circular image
*/
@Nullable private Bitmap getBitmapForView() {
Drawable drawable = getDrawable();
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
else {
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
drawable.draw(new Canvas(bm));
return bm;
}
}
代码示例来源:origin: jdsjlzx/LRecyclerView
public static void drawBottom(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) {
final int left = child.getLeft() - params.leftMargin - drawable.getIntrinsicWidth();
final int right = child.getRight() + params.rightMargin + drawable.getIntrinsicWidth();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + drawable.getIntrinsicHeight();
drawable.setBounds(left, top, right, bottom);
drawable.draw(canvas);
}
代码示例来源:origin: stackoverflow.com
Drawable image = context.getResources().getDrawable( R.drawable.ic_action );
int h = image.getIntrinsicHeight();
int w = image.getIntrinsicWidth();
image.setBounds( 0, 0, w, h );
button.setCompoundDrawables( image, null, null, null );
代码示例来源:origin: naman14/Timber
@Override
public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
if (mOrientation == VERTICAL_LIST) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
} else {
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
}
}
}
代码示例来源:origin: smuyyh/BookReader
public void drawVertical(Canvas c, RecyclerView parent) {
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getTop() - params.topMargin;
final int bottom = child.getBottom() + params.bottomMargin;
final int left = child.getRight() + params.rightMargin;
final int right = left + mDivider.getIntrinsicWidth();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
代码示例来源:origin: jdsjlzx/LRecyclerView
public static void drawLeft(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) {
final int top = child.getTop() - params.topMargin - drawable.getIntrinsicHeight();
final int bottom = child.getBottom() + params.bottomMargin + drawable.getIntrinsicHeight();
final int left = child.getLeft() - params.leftMargin - drawable.getIntrinsicWidth();
final int right = left + drawable.getIntrinsicWidth();
drawable.setBounds(left, top, right, bottom);
drawable.draw(canvas);
}
代码示例来源:origin: stackoverflow.com
myTextView.setText(Html.fromHtml(myText, new ImageGetter() {
@Override public Drawable getDrawable(String source) {
Drawable drawFromPath;
int path =
myActivity.this.getResources().getIdentifier(source, "drawable",
"com.package...");
drawFromPath = (Drawable) myActivity.this.getResources().getDrawable(path);
drawFromPath.setBounds(0, 0, drawFromPath.getIntrinsicWidth(),
drawFromPath.getIntrinsicHeight());
return drawFromPath;
}
}, null));
代码示例来源:origin: aa112901/remusic
@Override
public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
if (mOrientation == VERTICAL_LIST) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
} else {
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
}
}
}
代码示例来源:origin: Rukey7/MvpApp
public void drawVertical(Canvas c, RecyclerView parent) {
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getTop() - params.topMargin;
final int bottom = child.getBottom() + params.bottomMargin;
final int left = child.getRight() + params.rightMargin;
final int right = left + mDivider.getIntrinsicWidth();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
代码示例来源:origin: jdsjlzx/LRecyclerView
public static void drawTop(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) {
final int left = child.getLeft() - params.leftMargin - drawable.getIntrinsicWidth();
final int right = child.getRight() + params.rightMargin + drawable.getIntrinsicWidth();
final int top = child.getTop() - params.topMargin - drawable.getIntrinsicHeight();
final int bottom = top + drawable.getIntrinsicHeight();
drawable.setBounds(left, top, right, bottom);
drawable.draw(canvas);
}
代码示例来源:origin: stackoverflow.com
Drawable defaultMarker = r.getDrawable(R.drawable.icon);
// You HAVE to specify the bounds! It seems like the markers are drawn
// through Drawable.draw(Canvas) and therefore must have its bounds set
// before drawing.
defaultMarker.setBounds(0, 0, defaultMarker.getIntrinsicWidth(),
defaultMarker.getIntrinsicHeight());
MyItemizedOverlay markers = new MyItemizedOverlay(defaultMarker);
overlays.add(markers);
内容来源于网络,如有侵权,请联系作者删除!