如何在Button内使用android:drawableLeft填充顶部和底部空间

时间:2014-08-25 07:48:52

标签: android button android-widget android-xml

我正在使用android:drawableLeft将drawable放在按钮上,但是像这样:

enter image description here

如何使用按钮的高度match height of drawable

正如您所看到的,我正在通过我的脸书图标获取space on top and bottom,但我want to fill this space

看看我在用什么:

<LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:orientation="vertical"
        android:paddingBottom="5dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="5dp" >

        <Button
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:background="@drawable/fb_bg"
            android:text="Login with Facebook"
            android:drawableLeft="@drawable/fb_icon"
            android:layout_marginBottom="5dp"
            android:drawablePadding="0dp"
            android:textColor="@android:color/background_light"
            android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

fb_iconfb_bgdrawables大小相同 - 40 x 40

1 个答案:

答案 0 :(得分:0)

删除父级的填充和Button

的边距

使用此

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:orientation="vertical"
    android:paddingLeft="20dp"
    android:paddingRight="20dp" >

    <Button
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:background="@drawable/fb_bg"
        android:text="Login with Facebook"
        android:drawableLeft="@drawable/fb_icon"
        android:drawablePadding="0dp"
        android:textColor="@android:color/background_light"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>