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

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

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

Drawable.getBounds介绍

暂无

代码示例

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
  mState = newState;
  if (newState == RefreshState.None) {
    mAppreciation = 0;
    mCloudX1 = mCloudX2 = mCloudX3 = -mCloudDrawable.getBounds().width();
  }
}

代码示例来源:origin: facebook/litho

private static int getWidthForMountedContent(Object content) {
 return content instanceof Drawable ?
   ((Drawable) content).getBounds().width() :
   ((View) content).getWidth();
}

代码示例来源:origin: facebook/litho

private static int getHeightForMountedContent(Object content) {
 return content instanceof Drawable ?
   ((Drawable) content).getBounds().height() :
   ((View) content).getHeight();
}

代码示例来源:origin: facebook/litho

public static void applyXYToDrawableForAnimation(Drawable drawable, int x, int y) {
  final Rect bounds = drawable.getBounds();
  drawable.setBounds(x, y, bounds.width() + x, bounds.height() + y);
 }
}

代码示例来源:origin: scwang90/SmartRefreshLayout

public void setGeometricHeight(int height) {
  final Drawable drawable = PathsDrawable.this;
  final Rect bounds = drawable.getBounds();
  float rate = 1f * height / bounds.height();
  setBounds(
      (int) (bounds.left * rate),
      (int) (bounds.top * rate),
      (int) (bounds.right * rate),
      (int) (bounds.bottom * rate)
  );
}

代码示例来源:origin: scwang90/SmartRefreshLayout

public void setGeometricWidth(int width) {
  final Drawable drawable = PathsDrawable.this;
  final Rect bounds = drawable.getBounds();
  float rate = 1f * width / bounds.width();
  setBounds(
      (int) (bounds.left * rate),
      (int) (bounds.top * rate),
      (int) (bounds.right * rate),
      (int) (bounds.bottom * rate)
  );
}

代码示例来源:origin: scwang90/SmartRefreshLayout

public void declareOriginal(int startX, int startY, int width, int height) {
  this.mStartX = startX;
  this.mStartY = startY;
  this.mOriginWidth = mWidth = width;
  this.mOriginHeight = mHeight = height;
  final Drawable drawable = PathsDrawable.this;
  final Rect bounds = drawable.getBounds();
  super.setBounds(bounds.left, bounds.top, bounds.left + width, bounds.top + height);
}

代码示例来源:origin: scwang90/SmartRefreshLayout

private void drawSky(Canvas canvas, int width, int height) {
    Matrix matrix = mMatrix;
    matrix.reset();

    int bWidth = mDrawableSky.getBounds().width();//mSky.getWidth();
    int bHeight = mDrawableSky.getBounds().height();//mSky.getHeight();
    float townScale = 1f * width / bWidth;
    float offsetX = 0;
    float offsetY = height / 2 - bHeight / 2;

//        matrix.postScale(townScale, townScale);
//        matrix.postTranslate(offsetX, offsetY);
//
//        canvas.drawBitmap(mSky, matrix, null);

    final int saveCount = canvas.getSaveCount();
    canvas.save();
    canvas.translate(offsetX, offsetY);
    matrix.postScale(townScale, townScale);
    mDrawableSky.draw(canvas);
    canvas.restoreToCount(saveCount);
  }

代码示例来源:origin: facebook/litho

public static void applySizeToDrawableForAnimation(Drawable drawable, int width, int height) {
 final Rect bounds = drawable.getBounds();
 drawable.setBounds(bounds.left, bounds.top, bounds.left + width, bounds.top + height);
 // TODO(t22432769): Remove this after D5965597 lands
 if (drawable instanceof MatrixDrawable) {
  ((MatrixDrawable) drawable).bind(width, height);
 }
}

代码示例来源:origin: scwang90/SmartRefreshLayout

private void drawTown(Canvas canvas, int width, int height) {
    Matrix matrix = mMatrix;
    matrix.reset();

    int bWidth = mDrawableTown.getBounds().width();//mTown.getWidth();
    int bHeight = mDrawableTown.getBounds().height();//mTown.getHeight();
    float townScale = 1f * width / bWidth;
    float amplification = (0.3f * Math.max(mPercent - 1, 0) + 1);
    float offsetX = width / 2 - (int) (width * amplification) / 2;
    float offsetY = mHeaderHeight * 0.1f * mPercent;
    townScale = amplification * townScale;

    if (offsetY + bHeight * townScale < height) {
      offsetY = height - bHeight * townScale;
    }

//        matrix.postScale(townScale, townScale, mDrawableTown.getBounds().width() / 2, mDrawableTown.getBounds().height() / 2);
//        matrix.postTranslate(offsetX, offsetY);
//        canvas.drawBitmap(mTown, matrix, null);

    final int saveCount = canvas.getSaveCount();
    canvas.save();
    canvas.translate(offsetX, offsetY);
    canvas.scale(townScale, townScale);
    mDrawableTown.draw(canvas);
    canvas.restoreToCount(saveCount);
  }

代码示例来源:origin: aa112901/remusic

@Override
public void setThumb(Drawable thumb) {
  Rect localRect = null;
  if (drawable != null) {
    localRect = drawable.getBounds();
  }
  super.setThumb(drawable);
  drawable = thumb;
  if ((localRect != null) && (drawable != null)) {
    drawable.setBounds(localRect);
  }
}

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
protected void dispatchDraw(Canvas canvas) {
  super.dispatchDraw(canvas);
  final View thisView = this;
  final View dropView = mWaterDropView;
  final Drawable progressDrawable = mProgressDrawable;
  if (mState == RefreshState.Refreshing) {
    canvas.save();
    canvas.translate(
        thisView.getWidth()/2-progressDrawable.getBounds().width()/2,
        mWaterDropView.getMaxCircleRadius()
            +dropView.getPaddingTop()
            -progressDrawable.getBounds().height()/2
    );
    progressDrawable.draw(canvas);
    canvas.restore();
  }
}

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
public void draw(@NonNull Canvas c) {
  final Drawable thisDrawable = this;
  final Rect bounds = thisDrawable.getBounds();
  final int saveCount = c.save();
  c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
  mRing.draw(c, bounds);
  c.restoreToCount(saveCount);
}

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  final View thisView = this;
  final Drawable drawable = mPathsDrawable;
  super.setMeasuredDimension(
      View.resolveSize(drawable.getBounds().width()+thisView.getPaddingLeft()+thisView.getPaddingRight(), widthMeasureSpec),
      View.resolveSize(drawable.getBounds().height()+thisView.getPaddingTop()+thisView.getPaddingBottom(), heightMeasureSpec));
}

代码示例来源:origin: scwang90/SmartRefreshLayout

private void calculateFrame(int width) {
  mCloudX1 += DensityUtil.dp2px(9);
  mCloudX2 += DensityUtil.dp2px(5);
  mCloudX3 += DensityUtil.dp2px(12);
  int cloudWidth = mCloudDrawable.getBounds().width();
  if (mCloudX1 > width + cloudWidth) {
    mCloudX1 = -cloudWidth;
  }
  if (mCloudX2 > width + cloudWidth) {
    mCloudX2 = -cloudWidth;
  }
  if (mCloudX3 > width + cloudWidth) {
    mCloudX3 = -cloudWidth;
  }
  mAppreciation += 0.1f;
  final View thisView = this;
  thisView.invalidate();
}

代码示例来源:origin: facebook/litho

@Before
public void setup() throws DisplayListException {
 mDisplayList = Mockito.mock(DisplayList.class);
 mDrawable = Mockito.mock(Drawable.class);
 mCanvas = Mockito.mock(Canvas.class);
 mDlCanvas = Mockito.mock(Canvas.class);
 when(mDisplayList.isValid()).thenReturn(true);
 when(mDrawable.getBounds()).thenReturn(new Rect());
 when(mDisplayList.start(anyInt(), anyInt())).thenReturn(mDlCanvas);
}

代码示例来源:origin: facebook/litho

@Override
public void invalidateDrawable(Drawable who) {
 logDebug("Invalidating drawable", true);
 invalidateSelf();
 if (mIgnoreInvalidations) {
  return;
 }
 // We need to make sure at this point that the bounds of the  {@link DisplayListDrawable} are
 // equals to the bounds of its content to make sure that the view invalidation works as
 // expected.
 setBounds(mDrawable.getBounds());
 invalidateDL(); // DL needs to be re-created
}

代码示例来源:origin: facebook/litho

private void unmountDrawable(MountItem mountItem) {
 assertMainThread();
 final Drawable drawable = (Drawable) mountItem.getMountableContent();
 drawable.setCallback(null);
 invalidate(drawable.getBounds());
 releaseScrapDataStructuresIfNeeded();
}

代码示例来源:origin: facebook/litho

@Test
public void testMountedDrawableBounds() {
 final LithoView lithoView =
   mountComponent(
     mContext,
     new InlineLayoutSpec() {
      @Override
      protected Component onCreateLayout(ComponentContext c) {
       return create(c).widthPx(10).heightPx(10).build();
      }
     });
 assertThat(lithoView.getDrawables().get(0).getBounds()).isEqualTo(new Rect(0, 0, 10, 10));
}

代码示例来源:origin: robolectric/robolectric

@Test
public void mutate_createsDeepCopy() throws Exception {
 BitmapDrawable original = (BitmapDrawable) resources.getDrawable(R.drawable.an_image);
 Drawable mutated = original.mutate();
 assertThat(original).isNotSameAs(mutated);
 assertThat(mutated instanceof BitmapDrawable).isTrue();
 assertThat(mutated.getIntrinsicHeight()).isEqualTo(original.getIntrinsicHeight());
 assertThat(mutated.getIntrinsicWidth()).isEqualTo(original.getIntrinsicWidth());
 assertThat(mutated.getBounds()).isEqualTo(original.getBounds());
}

相关文章