如何制作左上角圆角和左下角圆角的形状?

问题描述:

我想要的形状与左上圆角和左下圆角:如何制作左上角圆角和左下角圆角的形状?

<?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> 

但形状上面没给我我想要的东西。它给了我一个没有任何圆角的矩形。

任何人都可以帮忙吗?

谢谢。

它看起来像一个错误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"/> 

我必须指定机器人:bottomRightRadius = “2DP” 的左下方圆角(另一个bug这里)。

+1

是的,我可以确认你的最后一个声明/错误,左/右切换那里。我在我的应用中也经历过同样的情况。 (sdk 2.1)。您是否已经为b.android.com提交了一个错误报告,或者是否已经在那里报告过? – 2010-06-17 01:30:14

+3

我刚刚提交了一个错误,http://code.google.com/p/android/issues/detail?id=9161。 可悲的是,他们修复了这个错误后,我必须再次更改我的代码:( – user256239 2010-06-17 17:30:35

您也可以为您的半径使用极小的数字。

<corners 
    android:bottomRightRadius="0.1dp" android:bottomLeftRadius="2dp" 
android:topLeftRadius="2dp" android:topRightRadius="0.1dp" /> 
+0

这是我第一次尝试...但没有希望....我在Android 2.2上测试...任何其他想法......谢谢 – 2012-12-25 05:44:11

尽管这个问题已经已经回答(这是导致bottomLeftRadius和bottomRightRadius一个bug被逆转),该bug已被固定在机器人3.1(API等级12 - 在模拟器上测试)。

因此,为了确保您的绘图在所有平台上都看起来正确,您应该在res/drawable-v12文件夹中放置“更正”版本的绘图(即xml中左下角/右半径实际上是正确的)你的应用。这样,所有使用Android版本> = 12的设备都将使用正确的可绘制文件,而使用旧版Android的设备将使用位于res/drawables文件夹中的“解决方法”drawable。

+0

今天碰到这个确切的问题多么烦人的bug – onit 2012-02-09 20:41:53

+0

+1感谢它对我非常有用 – Praveenkumar 2012-09-05 05:22:09

+5

这应该被接受为答案 – Abx 2013-10-08 07:19:41

documentation

注:每一个角落都必须(最初)被超过1提供一个拐角半径更大,否则没有边角圆润。如果你想要特定的 角不被舍入,一个解决方法是使用android:radius到 设置一个大于1的默认角半径,然后用你真正想要的值覆盖每个角和 ,提供零( “0dp”) 你不想要圆角。

例如,你必须设置一个机器人:半径=“”要能够做到你想要什么:

<corners 
    android:radius="2dp" 
    android:bottomRightRadius="0dp" 
    android:topRightRadius="0dp"/> 

另一个GOTCHA是,如果你做这样的事情,Eclipse中的预览是不正确的。您实际上必须启动您的应用才能看到实际结果!

+0

只是想在eclipse中指出3.7.2预览对我来说很不错 – kyle 2014-09-25 20:27:56

此错误提交here。 这是API级别小于12的Android设备的一个bug。 您必须将正确版本的布局放置在drawable-v12文件夹中,该文件夹将用于API级别12或更高级别。 相同布局的错误版本(角切换/反转)将放在默认的可绘制文件夹中,该文件夹将被API级别低于12的设备使用。

例如:我不得不设计一个按钮在右下角有圆角。

在'drawable'文件夹中 - button.xml:我不得不使左下角变圆。

<shape> 
    <corners android:bottomLeftRadius="15dp"/> 
</shape> 

在“可绘制-V12”文件夹 - button.xml:布局的正确版本被放在这里要用于API级12或更高。

<shape> 
    <corners android:bottomLeftRadius="15dp"/> 
</shape> 

他人有任何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> 

浅色结果向您展示三个项目:

enter image description here

最终结果:

enter image description here

此致敬意。

+0

非常感谢:) – 2015-05-30 15:22:47