I want to rotate drawableLeft in a TextView.
I tried this code:
Drawable result = rotate(degree);
setCompoundDrawables(result, null, null, null);
private Drawable rotate(int degree)
{
Bitmap iconBitmap = ((BitmapDrawable)originalDrawable).getBitmap();
Matrix matrix = new Matrix();
matrix.postRotate(degree);
Bitmap targetBitmap = Bitmap.createBitmap(iconBitmap, 0, 0, iconBitmap.getWidth(), iconBitmap.getHeight(), matrix, true);
return new BitmapDrawable(getResources(), targetBitmap);
}
But it gives me a blank space on the left drawable's place.
Actually, even this simplest code gives blank space:
Bitmap iconBitmap = ((BitmapDrawable)originalDrawable).getBitmap();
Drawable result = new BitmapDrawable(getResources(), iconBitmap);
setCompoundDrawables(result, null, null, null);
This one works fine:
setCompoundDrawables(originalDrawable, null, null, null);
According to the docs, if you want to set drawableLeft you should call setCompoundDrawablesWithIntrinsicBounds (int left, int top, int right, int bottom). Calling setCompoundDrawables() only works if setBounds() has been called on the Drawable, which is probably why your originalDrawable works.
So change your code to:
Drawable result = rotate(degree);
setCompoundDrawablesWithIntrinsicBounds(result, null, null, null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With