【发布时间】:2012-07-03 09:10:29
【问题描述】:
我试图让布局看起来像它
看起来有点像按钮类型。如何在按钮中同时实现文本和图像?
【问题讨论】:
我试图让布局看起来像它
看起来有点像按钮类型。如何在按钮中同时实现文本和图像?
【问题讨论】:
将您的自定义按钮创建为:
步骤 1: 在 res/drawable/button_background.xml 中创建一个 Button 可绘制形状 xml:
<?xml version=”1.0″ encoding=”UTF-8″?>
<shape xmlns:android=”http://schemas.android.com/apk/res/android”>
<solid android:color=”#F000″/>
<stroke android:width=”1px” android:color=”#BB000000″ />
<padding
android:left=”10dp”
android:top=”7dp”
android:right=”10dp”
android:bottom=”7dp”
/>
<corners
android:bottomRightRadius=”5dp”
android:bottomLeftRadius=”5dp”
android:topLeftRadius=”5dp”
android:topRightRadius=”5dp”
/>
<gradient
android:angle=”90″
android:startColor=”#777″
android:centerColor=”#777″
android:endColor=”#BBB”
android:type=”linear”
/>
</shape>
第 2 步: 将主 Button xml 布局添加为:
<Button android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Facebook"
android:drawableLeft="@drawable/leftimg"
android:drawableRight="@drawable/rightimg"
android:padding="15dip"
android:background="@drawable/button_background"/>
【讨论】:
android:drawableRight="@drawable/rightimg" 不会使图像完全正确
你可以在你的按钮android:drawableLeft="@drawable/your_icon"中做到这一点
【讨论】: