android.graphics.drawable.Drawable.setBounds()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(290)

本文整理了Java中android.graphics.drawable.Drawable.setBounds()方法的一些代码示例,展示了Drawable.setBounds()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Drawable.setBounds()方法的具体详情如下:
包路径:android.graphics.drawable.Drawable
类名称:Drawable
方法名:setBounds

Drawable.setBounds介绍

暂无

代码示例

代码示例来源: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: stackoverflow.com

Drawable d = getResources().getDrawable(R.drawable.foobar);
d.setBounds(left, top, right, bottom);
d.draw(canvas);

代码示例来源: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: stackoverflow.com

int bottom = top + divider.getIntrinsicHeight();
divider.setBounds(left, top, right, bottom);
divider.draw(c);

代码示例来源: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: 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: jdsjlzx/LRecyclerView

public static void drawBottomAlignItem(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) {
  final int left = child.getLeft() - params.leftMargin;
  final int right = child.getRight() + params.rightMargin;
  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: stackoverflow.com

int px = getResources().getDimensionPixelSize(R.dimen.map_dot_marker_size);
mDotMarkerBitmap = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(mDotMarkerBitmap);
Drawable shape = getResources().getDrawable(R.drawable.map_dot_red);
shape.setBounds(0, 0, mDotMarkerBitmap.getWidth(), mDotMarkerBitmap.getHeight());
shape.draw(canvas);

代码示例来源: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: jdsjlzx/LRecyclerView

public static void drawRight(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.getRight() + params.rightMargin;
  final int right = left + drawable.getIntrinsicWidth();
  drawable.setBounds(left, top, right, bottom);
  drawable.draw(canvas);
}

代码示例来源:origin: naman14/Timber

public void drawVertical(Canvas c, RecyclerView parent) {
  final int left = parent.getPaddingLeft();
  final int right = parent.getWidth() - parent.getPaddingRight();
  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.getBottom() + params.bottomMargin;
    final int bottom = top + mDivider.getIntrinsicHeight();
    mDivider.setBounds(left, top, right, bottom);
    mDivider.draw(c);
  }
}

代码示例来源: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: chentao0707/SimplifyReader

void drawOverscrollHeader(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.top = bounds.bottom - height;
  }
  drawable.setBounds(bounds);
  drawable.draw(canvas);
  canvas.restore();
}

代码示例来源: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 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: jdsjlzx/LRecyclerView

public static void drawTopAlignItem(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) {
  final int left = child.getLeft() - params.leftMargin;
  final int right = child.getRight() + params.rightMargin;
  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

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: chentao0707/SimplifyReader

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();
}

代码示例来源: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);
  }
}

相关文章