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"/>

猜你喜欢

转载自blog.csdn.net/luoguopeng/article/details/82897314
今日推荐