android:设置单个角点时,形状角点不起作用

android:设置单个角点时,形状角点不起作用,android,Android,我需要有一个具有圆形左下角/右下角圆锥体(但不是左上角/右上角圆锥体)的背景,下面是我的xml文件: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle" android:padding="1dp"&g

我需要有一个具有圆形左下角/右下角圆锥体(但不是左上角/右上角圆锥体)的背景,下面是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle" android:padding="1dp">
        <solid android:color="#FFbdbebd"/>
        <corners
            android:bottomLeftRadius="12dip"
            android:bottomRightRadius="12dip"
            android:topLeftRadius="0dip"
            android:topRightRadius="0dip"/>
    </shape>
</item>
</layer-list>
然后所有的角都是圆的,我搜索并发现了一个与此相关的bug:

但bug指出:

左/右切换,因为android:bottomRightRadius=“2dp”用于指定左下圆角

这可能与我的问题无关,我还尝试使用:

android:radius="12dip"

android:topLeftRadius="0dip"
android:topRightRadius="0dip"
没有成功


有人能帮忙吗?谢谢

试试这个对我来说很管用

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">
        <solid android:color="#FFFFFF"/>
        <corners 
            android:bottomRightRadius="30dp" 
            android:bottomLeftRadius="30dp"
            android:topLeftRadius="30dp" 
            android:topRightRadius="30dp"/>
</shape>


我发现可能存在一个错误,如果设置单个角点,如果其中任何一个角点为0,则所有角点都变为0,因此最后我将其中两个角点设置为1dip,其他两个角点设置为我需要的任何角点,因为它们都不是0,因此错误不会影响它,结果看起来不错。

这似乎是一个已知问题。每个角必须大于1,否则将不圆角。根据Android文档,这是可以做到的,但有点骇人:

注意:每个角(最初)必须提供大于1的角半径,否则没有圆角。如果您希望特定的角点不被圆角,解决方法是使用android:radius将默认角点半径设置为大于1,然后使用您真正想要的值覆盖每个角点,在您不想要>圆角的地方提供零(“0dp”)

请看这里: 更改此选项:

 <corners 
        android:bottomRightRadius="12dp" 
        android:bottomLeftRadius="12dp"
        android:topLeftRadius="0dp" 
        android:topRightRadius="0dp"/>

为此:

 <corners 
        android:radius="1dp"
        android:bottomRightRadius="12dp" 
        android:bottomLeftRadius="12dp"
        android:topLeftRadius="0dp" 
        android:topRightRadius="0dp"/>


而且它应该像预期的那样工作。

上述解决方案对我不起作用,但我在网上找到了一个可行的解决方案:()

这是为了仅将顶角四舍五入:

val image = findViewById<ImageView>(R.id.image)
val curveRadius = 20F

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

    image.outlineProvider = object : ViewOutlineProvider() {

        @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
        override fun getOutline(view: View?, outline: Outline?) {
            outline?.setRoundRect(0, 0, view!!.width, (view.height+curveRadius).toInt(), curveRadius)
        }
    }

    image.clipToOutline = true

}
val image=findviewbyd(R.id.image)
val curveRadius=20F
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.LOLLIPOP){
image.outlineProvider=对象:ViewOutlineProvider(){
@RequiresApi(Build.VERSION\u code.LOLLIPOP)
覆盖大纲(视图:视图?,大纲:大纲?){
轮廓?.setRoundRect(0,0,视图!!.width,(视图.高度+曲线半径).toInt(),曲线半径)
}
}
image.cliptoutline=true
}

如果我将四个角设置为圆角,它也适用于我,但问题是我只希望底部的两个角圆角,这两个角不起作用。android:radius=“1dp”会将所有角半径设置为1dp。或者可以简单地设置为。。不是虫子。如《开发指南》中所述。
val image = findViewById<ImageView>(R.id.image)
val curveRadius = 20F

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

    image.outlineProvider = object : ViewOutlineProvider() {

        @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
        override fun getOutline(view: View?, outline: Outline?) {
            outline?.setRoundRect(0, 0, view!!.width, (view.height+curveRadius).toInt(), curveRadius)
        }
    }

    image.clipToOutline = true

}