1. 程式人生 > >TextView的setCompoundDrawables不顯示問題解決

TextView的setCompoundDrawables不顯示問題解決

 TextView可以用過呼叫setCompoundDrawables設定一張圖片出現在上下左右四個地方。程式碼如下:

 Drawable drawable = getResources().getDrawable(R.drawable.delete_circle);
 
 //drawable.setBounds(0, 0, 32, 32);
 drawable.setBounds(0, 0, mDeleteIcon.getMinimumWidth(), mDeleteIcon.getMinimumHeight());

 //設定需要現實的位置 , 不需要顯示的 直接填null 即可 
 textView.setCompoundDrawables(drawable, null, null, null);

 注意 : 到這個Drawables必須已經呼叫過了setBounds。如果不設定則無法顯示。

安卓開發交流群:安卓幫595856941