矩形圆角的最大值 Android
Max value for rectangle's rounded corners in Android
我想得到如图所示的形状,一个角完全圆的矩形:
但是我好像不能得到角"rounder"比这个图:
这是为什么? <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>
好吧,我喜欢挠头几个小时,然后我在这里问了一个问题,然后我在不到 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>
<?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
值
我想得到如图所示的形状,一个角完全圆的矩形:
但是我好像不能得到角"rounder"比这个图:
这是为什么? <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>
好吧,我喜欢挠头几个小时,然后我在这里问了一个问题,然后我在不到 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>
<?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
值