天天看點

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。如果不設定則無法顯示。