Android

时间:2015-04-22 14:00:00

标签: android android-layout shape

我正在尝试获得如图所示的形状,一个角落完全是圆形的矩形: enter image description here

但似乎我无法获得角落"圆形"比这个数字:

enter image description here

为什么? <corners android:radius="integer" />有最大值? 当然我可以用png做到这一点,但我想使用一个形状更有效率,所以我更喜欢。

我的代码:

<Button
    android:id="@+id/button_guest"
    android:layout_width="315dp"
    android:layout_height="80dp"
    android:background="@drawable/rounded_rectangle"
    android:contentDescription="@string/text_button_guest"
    android:onClick="startGuestMode"
    android:text="@string/text_button_normal"
    android:textAllCaps="false"
    android:textColor="#ff000000"
    android:textSize="50sp"
    android:layout_marginLeft="125dp"
    android:layout_marginStart="125dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

rounded_rectangle.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffffff" />
    <corners
        android:radius="40dp" />
</shape>

2 个答案:

答案 0 :(得分:9)

好的,我爱我的头几个小时,然后我最终在这里问了一个问题,然后我在不到10分钟的时间里找到了答案:D

解决方案在我的代码中。你会认为它应该具有相同的行为,但显然它没有。可能是圆角的另一个错误。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffffff" />
    <corners
        android:bottomLeftRadius="40dp"
        android:bottomRightRadius="40dp"
        android:topRightRadius="40dp"
        android:topLeftRadius="40dp"
        />
</shape>

答案 1 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffffff" />
    <corners android:radius="1500dp" />
</shape>

将半径设置为最大值,它将在所有可绘制对象中起作用,这样,您实际上就不必依赖view height