use*_*239 77 android android-shape
我想制作一个带有左上角圆角和左下角圆角的形状:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#555555"/>
<stroke android:width="3dp"
android:color="#555555"
/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>
<corners android:bottomRightRadius="0dp" android:bottomLeftRadius="2dp"
android:topLeftRadius="2dp" android:topRightRadius="0dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
但上面的形状没有给我我想要的东西.它给了我一个没有任何圆角的矩形.
有人可以帮忙吗?
谢谢.
Geo*_*off 57
虽然已经回答了这个问题(这是一个导致bottomLeftRadius和bottomRightRadius被反转的错误),但这个bug已经在android 3.1(api level 12 - 在模拟器上测试)中得到修复.
因此,为了确保您的drawable在所有平台上看起来都正确,您应该在应用程序的res/drawable-v12文件夹中放置drawables的"更正"版本(即xml中左下角/右半径实际上是正确的).这样,使用android版本> = 12的所有设备都将使用正确的可绘制文件,而使用旧版本android的设备将使用位于res/drawables文件夹中的"workaround"drawable.
use*_*239 51
它看起来像一个错误http://code.google.com/p/android/issues/detail?id=939.
最后我要写这样的东西:
<stroke android:width="3dp"
android:color="#555555"
/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>
<corners android:radius="1dp"
android:bottomRightRadius="2dp" android:bottomLeftRadius="0dp"
android:topLeftRadius="2dp" android:topRightRadius="0dp"/>
Run Code Online (Sandbox Code Playgroud)
我必须为左下角圆角指定android:bottomRightRadius ="2dp"(这里是另一个错误).
Ent*_*eco 30
从文档:
注意:每个角必须(最初)提供大于1的角半径,否则没有角是圆角.如果你想要特定的角不被舍入,一个解决方法是使用android:radius来设置一个大于1的默认角半径,但是然后使用你真正想要的值覆盖每个角,提供零("0dp") )你不想要圆角.
例如,你必须设置一个android:radius =""才能做你想要的:
<corners
android:radius="2dp"
android:bottomRightRadius="0dp"
android:topRightRadius="0dp"/>
Run Code Online (Sandbox Code Playgroud)
另一个GOTCHA,就是如果你做这种事情,eclipse中的预览是不正确的.您实际上必须启动您的应用程序才能看到实际结果!
Mon*_*der 14
你也可以使用极小的数字作为你的半径.
<corners
android:bottomRightRadius="0.1dp" android:bottomLeftRadius="2dp"
android:topLeftRadius="2dp" android:topRightRadius="0.1dp" />
Run Code Online (Sandbox Code Playgroud)
小智 10
对于其他人,有任何API级别的解决方案,您可以将项目放在彼此的顶部示例:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- my firt item with 4 corners radius(8dp)
-->
<item>
<shape>
<solid
android:angle="270.0"
android:color="#3D689A" />
<corners android:topLeftRadius="8dp" />
</shape>
</item>
<!-- my second item is on top right for a fake corner radius(0dp)
-->
<item
android:bottom="30dp"
android:left="50dp">
<shape>
<solid android:color="#5C83AF" />
</shape>
</item>
<!-- my third item is on bottom left for a fake corner radius(0dp)
-->
<item
android:right="50dp"
android:top="30dp">
<shape>
<solid android:color="#5C83AF" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
浅色的结果向您展示了三个项目:
最终结果:
最好的祝福.
此错误在此处提交.这是Android级别小于12的Android设备的错误.您必须在drawable-v12文件夹中放置正确版本的布局,该文件夹将用于API级别12或更高级别.并且相同布局的错误版本(角点切换/反转)将被放入默认的可绘制文件夹中,该文件夹将由API级别小于12的设备使用.
例如:我必须在右下角设计一个带圆角的按钮.
在'drawable'文件夹中 - button.xml:我必须使左下角圆滑.
<shape>
<corners android:bottomLeftRadius="15dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
在'drawable-v12'文件夹中 - button.xml:此处放置了正确版本的布局,用于API级别12或更高级别.
<shape>
<corners android:bottomLeftRadius="15dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
尝试这个
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/upkia"/>
<corners android:radius="10dp"
android:topRightRadius="0dp"
android:bottomRightRadius="0dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
87482 次 |
| 最近记录: |