Android Button 背景高度被拉伸问题

            <Button
                android:text="我是按钮"
                android:textColor="@color/white"
                android:textSize="12sp"
                android:background="@drawable/bg_button_gray"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

bg_button_gray.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners android:radius="@dimen/qb_px_25" />

    <stroke android:color="@color/tran_gray3" android:width="@dimen/qb_px_2"/>
    <solid android:color="@color/trans" />
    <size android:width="@dimen/qb_px_400" android:height="@dimen/qb_px_50"/>

</shape>

bg_button_gray中设置的shape高度为50,可实际上的效果却远大于50。

原因:

Button中有默认的MinHeight和MinWidth,将MinHeight和MinWidth设置为0dp即可。

            <Button
                android:minWidth="0dp"
                android:minHeight="0dp"
                android:text="我是按钮"
                android:textColor="@color/white"
                android:textSize="12sp"
                android:background="@drawable/bg_button_gray"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值