您的位置:首页 > 其它

在TextView中设置DrawableLeft不显示的问题

2015-12-24 17:03 225 查看
1.在XML中使用 android:drawableLeft="@drawable/icon"

2.代码中动态变化 Drawable drawable= getResources().getDrawable(R.drawable.drawable);

/// 这一步必须要做,否则不会显示. drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); myTextview.setCompoundDrawables(drawable,null,null,null);

注意必须调用setBounds,才能腾出空间来显示drawableLeft的图片

以上代码等效于:

setCompoundDrawablesWithIntrinsicBounds (Drawable left,Drawable top, Drawable right, Drawable bottom)

Drawable的setBounds方法有四个参数,setBounds(int left, int top, int right, int bottom),这个四参数指的是drawable将在被绘制在canvas的哪个矩形区域内。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: