IMAGEBUTTON
其实派生自image view,而不是派生自button。,image view拥有的属性和方法,image button 统统拥有,只是imagebutton有个默认的按钮外观。
- image button 只能显示图形
- imagebutton 上面的图片可按比例拉伸
- 只能在背景显示一张图形,但分别在前景和背景显示两张图片,实现图片叠加的效果
- 在输入法无法输入的字符和特殊字体显示的字符串,就适合用imagebutton, 先切图再显示
- 要想在文字周围放图片可以用基于text view 的 button,
- 具体在xml中设置如下属性:
- drawableTop:指定文本上方的图片
- drawableBottom:指定文本下方的图片
- drawableLeft:指定文本左边的图形
- drawableRight:指定文本右边的图片
- drawablepadding:指定图形文本间距
- 在代码中:
- setCompoundDrawables:设置文本周围图形,上下左右
- setCompoundDrawablePadding:间距
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical"> 6 7 <Button 8 android:id="@+id/btn_icon" 9 android:layout_width="wrap_content" 10 android:layout_height="wrap_content" 11 android:layout_marginTop="10dp" 12 android:layout_gravity="center" 13 android:drawableLeft="@mipmap/ic_launcher" 14 android:drawablePadding="5dp" 15 android:text="热烈欢迎" 16 android:textColor