3

我正在尝试创建一个具有两个圆边和两个锐边的形状。但我不断收到以下错误:

The graphics preview in the layout editor may not be accurate:
Different corner sizes are not supported in Path.addRoundRect.

这是代码

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#888888" >
    </solid>

    <stroke
        android:width="2dp"
        android:color="#C4CDE0" >
    </stroke>

    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp" >
    </padding>

    <corners
        android:bottomLeftRadius="11dp"
        android:topLeftRadius="11dp" >
    </corners>

</shape>
4

5 回答 5

8

我也面临同样的问题。但为此我使用图层列表。我在这里发布我的答案,这可能会对您有所帮助。
请检查输出屏幕在此处输入图像描述

![<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
      <shape 
        android:shape="rectangle">
            <stroke android:width="1dp" android:color="#c1c1c1" />
            <solid android:color="#c1c1c1" />
            <corners android:radius="20dp"/>
        </shape>
   </item>

   <item android:right="20dp"
        >
      <shape 
        android:shape="rectangle">
            <stroke android:width="1dp" android:color="#c1c1c1" />
            <solid android:color="#c1c1c1" />
        </shape>
   </item>

</layer-list>][2]
于 2014-04-01T07:00:38.920 回答
2

shape我能够使用您定义的相同效果创建您正在寻找的效果。错误的措辞是;

“版面编辑器中的图形预览可能不准确: ”这仅用于预览。运行应用程序,它应该按预期呈现。

编辑

根据文件;

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.

这似乎是谷歌希望你实现形状的方式。我已经相应地修改了我的代码,没有问题。

于 2014-03-20T03:27:12.077 回答
1
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners
        android:topLeftRadius="10dp"
        android:bottomLeftRadius="10dp" />

    <solid android:color="#222224" />

</shape>
于 2015-04-20T07:14:43.690 回答
0

I just checked your code and used the same, for me it is working. Just cross check these things.

  1. Save shape.xml in \res\drawable folder.

  2. Set the background of Button in layout.

My lay-out file is

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

   <Button
    android:id="@+id/btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/shape"
    android:text="Click me" />

</LinearLayout>
于 2013-06-28T11:17:05.587 回答
0

使用这个在线工具非常有用

http://angrytools.com/android/button/

您的答案

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
      android:topLeftRadius="100dp"
      android:topRightRadius="100dp"
      android:bottomLeftRadius="0dp"
      android:bottomRightRadius="0dp"
 />
 <solid
      android:color="#2B9CB3"
 />
 <padding
      android:left="5dp"
      android:top="5dp"
      android:right="5dp"
      android:bottom="5dp"
 />
 <size
      android:width="270dp"
      android:height="60dp"
 />
 <stroke
      android:width="2dp"
      android:color="#FFFFFF"
  />
 </shape>

http://pastie.org/8952601

于 2014-03-20T05:47:25.323 回答