Android为一个控件设置DrawableLeft或其他三个方向的图片,一般采用两种方式。
- 静态设置(布局xml文件)
<Button
android:id="@+id/radioBtn0"
android:drawableTop="@drawable/radio_home_style"
android:text="@string/radio_home"
style="@style/main_tab_bottom"/>
- 动态设置
Button button = (Button) findViewById(R.id.btn);
Drawable img = getResources().getDrawable(R.drawable.image);
img.setBounds(0, 0, img_off.getMinimumWidth(), img_off.getMinimumHeight());
button.setCompoundDrawables(null, img, null, null);//设置该图片位置在上方