Drawable setBounds - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Drawable setBounds method.

This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth, setBounds
 
    final int width = bounds.width();
    final int height = bounds.height();
    final float ratio = (float) width / height;
 
    final int drawableWidth = drawable.getIntrinsicWidth();
    final int drawableHeight = drawable.getIntrinsicHeight();
    final float drawableRatio = (float) drawableWidth / drawableHeight;
 
    if (drawableRatio < ratio) {
      final float scale = (float) height / drawableHeight;
      final int scaledDrawableWidth = (int) (drawableWidth * scale);
      final int drawableLeft = bounds.left - (scaledDrawableWidth - width) / 2;
      final int drawableRight = drawableLeft + scaledDrawableWidth;
      drawable.setBounds(drawableLeft, bounds.top, drawableRight, bounds.bottom);
    } else { 
      final float scale = (float) width / drawableWidth;
      final int scaledDrawableHeight = (int) (drawableHeight * scale);
      final int drawableTop = bounds.top - (scaledDrawableHeight - height) / 2;
      final int drawableBottom = drawableTop + scaledDrawableHeight;

9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, getBounds, getIntrinsicHeight, getIntrinsicWidth, setBounds
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
                bitmapDrawable.setTargetDensity(mDisplayMetrics);
            } 
        } 
        int sourceWidth = icon.getIntrinsicWidth();
        int sourceHeight = icon.getIntrinsicHeight();
 
        if (sourceWidth > 0 && sourceHeight > 0) {
            // There are intrinsic sizes. 
            if (width < sourceWidth || height < sourceHeight) {
                // It's too big, scale it down. 
                final float ratio = (float) sourceWidth / sourceHeight;
                if (sourceWidth > sourceHeight) {
                    height = (int) (width / ratio);
                } else if (sourceHeight > sourceWidth) {
                    width = (int) (height * ratio);
                } 
            } else if (sourceWidth < width && sourceHeight < height) {
                // It's small, use the size they gave us. 

9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, setBounds
            drawVerticalDivider(canvas, right);
        } 
    } 
 
    private void drawHorizontalDivider(Canvas canvas, int top) {
        mDivider.setBounds(getPaddingLeft() + mDividerPadding, top,
                getWidth() - getPaddingRight() - mDividerPadding, top + mDividerHeight);
        mDivider.draw(canvas);
    } 
 
    private void drawVerticalDivider(Canvas canvas, int left) {
        mDivider.setBounds(left, getPaddingTop() + mDividerPadding,
                left + mDividerWidth, getHeight() - getPaddingBottom() - mDividerPadding);
        mDivider.draw(canvas);
    } 
 
    private boolean hasDividerBeforeChildAt(int childIndex) {
        if (childIndex == 0 || childIndex == getChildCount()) {
          return false; 
        } 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth, getPaint, setBounds
 
    public DrawableHolder(BitmapDrawable drawable, float x, float y) {
        mDrawable = drawable;
        mX = x;
        mY = y;
        mDrawable.getPaint().setAntiAlias(true); // Force AA
        mDrawable.setBounds(0, 0, mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight());
    } 
 
    /** 
     * 
     * Adds an animation that interpolates given property from its current value 
     * to the given value. 
     * 
     * @param duration the duration, in ms. 
     * @param delay the delay to start the animation, in ms. 
     * @param property the property to animate 
     * @param toValue the target value 
     * @param replace if true, replace the current animation with this one. 
     */ 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, setAlpha, setBounds
 
	@Override 
	public void draw(Canvas canvas)
	{ 
		if (background != null) {
			background.setBounds((int) innerRect.left, (int) innerRect.top, (int) innerRect.right, (int) innerRect.bottom);
		} 
 
		canvas.save();
 
		if (background != null) {
			if (alpha > NOT_SET) {
				background.setAlpha(alpha);
			} 
			background.draw(canvas);
		} 
 
		canvas.restore();
	} 
 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, setBounds, setState
	@Override 
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
 
		if (image != null) {
			image.setState(getDrawableState());
 
			// scale image to fit inside button 
 
			int imgHeight = image.getIntrinsicHeight();
			int imgWidth = image.getIntrinsicWidth();
			int btnWidth = getWidth();
			int btnHeight = getHeight();
			float scale;
 
			if (imgWidth <= btnWidth && imgHeight <= btnHeight) {
                scale = 1.0f;
            } else { 
                scale = Math.min((float) btnWidth / (float) imgWidth,
                        (float) btnHeight / (float) imgHeight);

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, getBounds, getIntrinsicHeight, getIntrinsicWidth, getOpacity
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
                bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
            } 
        } 
        int iconWidth = icon.getIntrinsicWidth();
        int iconHeight = icon.getIntrinsicHeight();
 
        if (width > 0 && height > 0) {
            if (width < iconWidth || height < iconHeight || scale != 1.0f) {
                final float ratio = (float) iconWidth / iconHeight;
 
                if (iconWidth > iconHeight) {
                    height = (int) (width / ratio);
                } else if (iconHeight > iconWidth) {
                    width = (int) (height * ratio);
                } 
 
                final Bitmap.Config c = icon.getOpacity() != PixelFormat.OPAQUE ?
                            Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, setBounds
            final int h = getHeight();
 
            frameBounds.set(0, 0, w, h);
            mFrame.setBounds(frameBounds);
            if (mOverlay != null) {
                mOverlay.setBounds(w - mOverlay.getIntrinsicWidth(),
                        h - mOverlay.getIntrinsicHeight(), w, h);
            } 
        } 
 
        mFrame.draw(canvas);
        if (mOverlay != null) {
            mOverlay.draw(canvas);
        } 
    } 
 
 
    @Override 
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth, setBounds
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
 
        mDrawable = drawable;
        if (mDrawable != null) {
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        } 
    } 
 
    public void setCenter(float x, float y) {
        mCenterX = x;
        mCenterY = y;
    } 
 
    public void makePointCloud(float innerRadius, float outerRadius) {
        if (innerRadius == 0) {
            Log.w(TAG, "Must specify an inner radius");
            return; 
        } 
        mOuterRadius = outerRadius;
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth, setBounds
 
        if (marker == null) {
            return null; 
        } 
 
        final int width = marker.getIntrinsicWidth();
        final int height = marker.getIntrinsicHeight();
 
        if (width < 0 || height < 0) {
            throw new IllegalStateException("The given Drawable has no intrinsic width or height");
        } 
 
        int left, top;
 
        switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
            case Gravity.LEFT:
                left = 0;
                break; 
            case Gravity.RIGHT:
                left = -width;

8
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Drawable setBounds Questions & Answers:

setBounds Method Overview
Specify a bounding rectangle for the Drawable.
See Code Examples for other Android Drawable Methods: