按钮中的圆形形状未正确显示

时间:2014-03-08 20:21:09

标签: android

对于第一个按钮的背景我使用了

以下的形状

1)left_round_shape_button.xml

<solid android:color="#0084ff" />

<corners
    android:radius="10dp"
    android:bottomLeftRadius="10dp"
    android:topLeftRadius="10dp"
    android:bottomRightRadius="0dp"
    android:topRightRadius="0dp" />

</shape>

用于设置我在下面的代码

中使用的第二个按钮的背景

2)right_round_shape_button.xml

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

<!-- you can use any color you want I used here gray color -->
<solid android:color="#0084ff" />

<corners
    android:radius="10dp"
    android:bottomLeftRadius="10dp"
    android:topLeftRadius="10dp"
    android:bottomRightRadius="0dp"
    android:topRightRadius="0dp" />

</shape>

现在我将其设置为按钮

  <LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/header"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btnSticker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/left_round_shape_button"
        android:text="Sticker"
        android:textColor="@android:color/white" />

    <Button
        android:id="@+id/btnMySticker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/right_round_shape_button"
        android:text="My Sticker" />
</LinearLayout>

但这些看起来不合适:(

enter image description here

为什么第一个按钮是圆形的,为什么第二个按钮不会出现:(

来自android docs我已阅读以下

Note: Every corner must (initially) be provided a corner radius greater than 1, or else no 
corners are rounded. If you want specific corners to not be rounded, a work-around is to use 
android:radius to set a default corner radius greater than 1, but then override each and every
corner with the values you really want, providing zero ("0dp") where you don't want rounded corners.

1 个答案:

答案 0 :(得分:0)

最后我得到了解决方案,这是XML渲染的问题,当你运行你的应用程序时,你会获得正确的输出,