【问题标题】:How to fill top and bottom space using android:drawableLeft inside Button如何在 Button 内使用 android:drawableLeft 填充顶部和底部空间
【发布时间】:2014-08-25 07:48:51
【问题描述】:

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

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

如您所见,我收到的是space on top and bottom,但我的 Facebook 图标是 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

【问题讨论】:

  • 要么使用相同大小的图像,要么删除android:layout_marginBottom="5dp" 以及线性布局的填充

标签: android button android-widget android-xml


【解决方案1】:

移除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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 2010-11-26
    • 2011-11-02
    • 1970-01-01
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多