android Button,textView 等控件設置控件內嵌周圍圖片使用方法

android Button,textView 等控件設置控件內嵌周圍圖片使用方法

....................................................................................................................................................................................................................................

1:在佈局中直接設置:

android:drawableLeft|Right|Top|Bottom

 android:drawablePadding="10dp"//圖片與控件文字內容距離設置

2:在代碼中動態設置:Drawable img_right,img_left,img_top,img_bottom;

a:獲取drawable:img_right=getResources().getDrawable(R.drawable.img_right);......

b:設置圖片(必須設置,不設置,圖片不顯示哦!):

img_right.setBounds(0, 0, img_right.getMinimumWidth(), img_right.getMinimumHeight());

c:button.setCompoundDrawables(null,null,img_right,null);

.................................................................................................................................................................................................................................................
相關文章
相關標籤/搜索