Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 将旋转的drawable设置为TextView的drawableLeft大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在TextView中旋转drawableLeft. @H_944_5@ @H_944_5@我试过这段代码

@H_944_5@ @H_801_9@Drawable result = rotate(degreE); setCompoundDrawables(result,null,null); private Drawable rotate(int degreE) { Bitmap iconBitmap = ((BitmapDrawablE)originalDrawablE).getBitmap(); Matrix matrix = new Matrix(); matrix.postRotate(degreE); Bitmap targetBitmap = Bitmap.createBitmap(iconBitmap,iconBitmap.getWidth(),iconBitmap.getHeight(),matrix,truE); return new BitmapDrawable(getresources(),targetBitmap); } @H_944_5@但它给了我左侧drawable的位置一个空白区域.

@H_944_5@实际上,即使这个最简单的代码也会给出空白:

@H_944_5@ @H_801_9@Bitmap iconBitmap = ((BitmapDrawablE)originalDrawablE).getBitmap(); Drawable result = new BitmapDrawable(getresources(),iconBitmap); setCompoundDrawables(result,null); @H_944_5@这个工作正常:

@H_944_5@ @H_801_9@setCompoundDrawables(originalDrawable,null);

解决方法

根据 the docs,如果你想设置drawableLeft,你应该调用 setCompoundDrawablesWithIntrinsicBounds (int left,int top,int right,int bottom).调用setCompoundDrawables()只有在Drawable上调用setBounds()时才有效,这可能是你的originalDrawable工作的原因. @H_944_5@ @H_944_5@所以将代码更改为:

@H_944_5@ @H_801_9@Drawable result = rotate(degreE); setCompoundDrawablesWithIntrinsicBounds(result,null);

大佬总结

以上是大佬教程为你收集整理的android – 将旋转的drawable设置为TextView的drawableLeft全部内容,希望文章能够帮你解决android – 将旋转的drawable设置为TextView的drawableLeft所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。