在我调用setCompoundDrawables
方法之后,未显示复合可绘制对象。
Drawable myDrawable = getResources().getDrawable(R.drawable.btn);
btn.setCompoundDrawables(myDrawable, null, null, null);
有什么想法吗?
发布于 2011-07-07 00:24:26
发布于 2014-10-19 16:03:05
使用这个(我测试过)。它运行良好
Drawable image = context.getResources().getDrawable( R.drawable.ic_action );
int h = image.getIntrinsicHeight();
int w = image.getIntrinsicWidth();
image.setBounds( 0, 0, w, h );
button.setCompoundDrawables( image, null, null, null );
发布于 2012-02-13 15:20:29
图像为空,因为它没有指定的边界。您可以使用setCompoundDrawables()
,但在指定图像的边界之前,请使用Drawable.setBounds()
方法
https://stackoverflow.com/questions/6590838
复制相似问题