我希望可以在TextView中旋转drawableLeft。
我尝试了以下代码:
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);
}
但是它在左侧绘制区域留下了一个空白。实际上,即使是这个最简单的代码也会产生空白:
Bitmap iconBitmap = ((BitmapDrawable)originalDrawable).getBitmap();
Drawable result = new BitmapDrawable(getResources(), iconBitmap);
setCompoundDrawables(result, null, null, null);
这个可以正常工作:
setCompoundDrawables(originalDrawable, null, null, null);