【问题标题】:Applying padding to custom button将填充应用于自定义按钮
【发布时间】:2013-05-05 03:55:37
【问题描述】:

我正在尝试制作没有填充的 mu 自定义按钮。为此,我创建了以下选择器:

 <?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true" >
        <shape>
            <solid 
                android:color="#33b5e5"/>
            <corners
                android:radius="1dp" />
            <padding
                android:left="0dp"
                android:top="0dp"
                android:right="0dp"
                android:bottom="0dp" />
        </shape>
    </item>

    <item android:state_focused="true" >
        <shape>
            <solid 
                android:color="#cccccc"/>
            <corners
                android:radius="1dp" />
            <padding
                android:left="0dp"
                android:top="0dp"
                android:right="0dp"
                android:bottom="0dp" />
        </shape>
    </item>

    <item>        
        <shape>
            <solid
                 android:color="#cccccc"/>
            <corners
                android:radius="1dp" />
            <padding
                android:left="0dp"
                android:top="0dp"
                android:right="0dp"
                android:bottom="0dp" />
        </shape>
    </item>
</selector>

我在 xml 文件中定义了我的按钮:

<Button 
        android:text="Some text"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/button_selector"
        android:textSize="45sp"

        android:paddingBottom="0dp"
        android:paddingTop="0dp"
        android:layout_margin="3dip"/>

但是按钮的顶部和底部总是有填充。我已经搜索过 SO 并找到了一些答案,但没有任何帮助。可能是什么问题?

【问题讨论】:

    标签: android-layout padding android-button


    【解决方案1】:

    设置边距对您的情况有帮助吗?试试这个:

         android:layout_marginTop="-3dip"
         android:layout_marginBottom="-3dip"
    

    【讨论】:

    • 这很有用。我尝试了负填充值,但忘记使用负边距进行测试。我尝试将它与以编程方式制作的按钮一起使用,但没有运气。您是否知道如何解决此问题?
    • @sinisha,如果你真的想摆脱它,创建你自己的9-patch
    • @sinisha,见How to set layout_margin programmatically?。这可能会有所帮助。
    • 感谢您的回答。我已经试过了,但是没有用
    猜你喜欢
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多