只有两个角被圆角化的ImageView?

14

我想要一个ImageView,它的右上角和左下角是圆角的。

<corners 
android:topRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="0dp"
android:bottomRightRadius="0dp"/>
尝试了上述代码,但它不起作用。请帮忙!

你如何将它们一起使用? - waqaslam
请建议如何使图像视图的右上角和左下角仅为圆角?Rohit @ 我已经做到了,但形状出现的是矩形,而不是两个角落被圆角化。 - vaibvorld
请查看以下链接:https://dev59.com/xHE95IYBdhLWcg3wGZ9_。 - Vishal Pawar
这不是一个真正的问题吗? - Mark
这是我能找到的最好的库。 - grrigore
显示剩余2条评论
2个回答

5
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@android:color/darker_gray"/>
<corners android:topRightRadius="10dp"
    android:bottomRightRadius="0dp"
    android:topLeftRadius="0dp"
    android:bottomLeftRadius="10dp"/>

</shape>

这是我在drawable文件夹中的drawable shape.xml。我将它用作imageview背景图片。
<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher"
    android:background="@drawable/shape"/>

完成后,当您在设备/模拟器上运行应用程序时,它将出现(在XML图形布局中不会出现)。


1
谢谢,我正在研究XML,在设备上运行良好。 - vaibvorld
1
我无法让它工作,除了这个之外还需要做什么吗? - Edmund Rojas
6
我认为这个方法行不通。你创建了一个带有圆角的背景,但是 ImageView 并没有改变。 - nucleartide
当然,这不会改变实际视图,但我刚刚解决了操作员所做的错误。 - Rohit
它可以为ImageView创建圆角,但不适用于其中的图像。 - ekashking
不会裁剪图像内容为圆形 - Asad

2
我正在使用这个,对我来说很好用。
<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >

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

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

        <stroke
            android:width="1dp"
            android:color="#000000" />

    </shape>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接