为什么我无法为特定角落创建圆形边框?

Shr*_*jan 18 android xml-layout

在我的android xml布局中,我使用borderframe.xml作为背景来应用边框.

borderframe.xml文件如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke 
        android:width="1dip" 
        android:color="#ffffff"/>
    <solid 
        android:color="#95865F"/>
    <corners 
        android:radius="10px"/>

    <padding 
        android:left="1dp"
        android:right="1dp"
        android:top="1dp"
        android:bottom="1dp"/> 
</shape>
Run Code Online (Sandbox Code Playgroud)

现在,虽然有一个android:radius ="10px"然后它是有效的,但我将圆形形状到特定的角落只有它不起作用.日志猫中没有任何错误消息,但我在eclipse中发现错误,如:

    The graphics preview in the layout editor may not be accurate:
* Different corner sizes are not supported in Path.addRoundRect.
Run Code Online (Sandbox Code Playgroud)

即使该xml文件中没有填充,我也无法看到任何边框.

现在,我该怎么做呢?如果我想为topLeftcorner和bottomLeftCorner创建圆形边框,那么它是什么的解决方案.?谢谢.

Amo*_*kar 17

我也面临同样的问题.但为此我使用了图层列表.我在这里发布我的答案可能对你有所帮助.
请检查输出屏幕图片1

<?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>
Run Code Online (Sandbox Code Playgroud)


Ren*_*aud 10

你必须这样做,假设你只想要一个圆角的左上角:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <corners
      android:radius="20sp"
      android:topRightRadius="0dp"
      android:bottomRightRadius="0dp"
      android:bottomLeftRadius="0dp" />
  <gradient
      android:startColor="@color/logo_blue"
      android:endColor="@color/blue"
      android:angle="0"/>
</shape>
Run Code Online (Sandbox Code Playgroud)

说明:每个角必须(最初)提供大于1的角半径,否则没有角是圆角.如果你想要特定的角不是圆角的,可以使用一种解决方法来android:radius设置一个大于1的默认角半径,然后使用你真正想要的值覆盖每个角,提供零("0dp")你在哪里不要圆角.[ 来源 ]

因此,您需要将drawable定义为:

<?xml version="1.0" encoding="UTF-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke 
        android:width="1dip" 
        android:color="#ffffff"/>
    <solid 
        android:color="#95865F"/>
    <corners 
       android:radius="10px"
      android:topRightRadius="0dp"
      android:bottomRightRadius="0dp" />

    <padding 
        android:left="1dp"
        android:right="1dp"
        android:top="1dp"
        android:bottom="1dp"/> 
</shape>
Run Code Online (Sandbox Code Playgroud)

更新

来自Shape Drawable Resource Android文档:

android:radius Dimension.所有角的半径,作为维值或维度资源.通过以下属性覆盖每个角落.

覆盖是您的问题的关键字...


Jop*_*aij 6

我正在使用SDK工具19,平台工具11并在Android 4.0.3中运行应用程序.使用以下XML对我有用:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
    <solid android:color="#dd000000"/>
    <padding 
        android:left="7dp"
        android:top="7dp"
        android:right="7dp"
        android:bottom="7dp" />
    <corners
        android:bottomLeftRadius="25dp"
        android:bottomRightRadius="25dp"
        android:topLeftRadius="0dp"
        android:topRightRadius="0dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)

Eclipse警告无法显示预览.在het app中它显示正确.