Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何设置图像视图的圆角?_Java_Android_Xml_Image_Imageview - Fatal编程技术网

Java 如何设置图像视图的圆角?

Java 如何设置图像视图的圆角?,java,android,xml,image,imageview,Java,Android,Xml,Image,Imageview,如何设置图像视图的圆角而不是内部图像 我试图使用glide设置ImageView的圆角,但glide仅设置图像的圆角,而不是ImageView 我在cardwiew中创建ImageView。我用“捏”按钮在ImageView中缩放手势。 当我使用glide设置ImageView的圆角时,请使用glide设置图像的圆角,而不是ImageView与CardView形状相同。您可以使用此库,它提供了许多形状,可以帮助您 首先在build.gradle(应用程序)中添加此依赖项 现在,为了获得圆角图像视

如何设置
图像视图的圆角
而不是内部图像

我试图使用glide设置
ImageView
的圆角,但glide仅设置图像的圆角,而不是
ImageView

我在
cardwiew
中创建
ImageView
。我用“捏”按钮在
ImageView
中缩放手势。 当我使用glide设置
ImageView
的圆角时,请使用glide设置图像的圆角,而不是
ImageView
CardView
形状相同。

您可以使用此库,它提供了许多形状,可以帮助您

首先在build.gradle(应用程序)中添加此依赖项

现在,为了获得圆角图像视图,您需要使用

<com.github.siyamed.shapeimageview.mask.PorterShapeImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:siShape="@drawable/shape_rounded_rectangle"
    android:src="@drawable/neo"
    app:siSquare="true"/>
要获得带有边框的矩形,只需使用

<com.github.siyamed.shapeimageview.RoundedImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/neo"
    app:siRadius="6dp"
    app:siBorderWidth="6dp"
    app:siBorderColor="@color/darkgray"
    app:siSquare="true"/>

以下是您得到的:


您可以覆盖自定义ImageView中的onDraw方法,并在画布上绘制RoundRect:

@覆盖
受保护的void onDraw(画布){
rect=newrectf(0,0,this.getWidth(),this.getHeight());
addRoundRect(rect,radius,radius,path.Direction.CW);
canvas.clipPath(路径);
super.onDraw(帆布);
}

谢谢你回答我。。。但我在图像视图中使用收缩缩放手势。我更新了我的问题。现在你可以试着answer@AkashAttal是否尝试将cardview角设置为圆角?
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
    <corners
        android:topLeftRadius="18dp"
        android:topRightRadius="18dp"
        android:bottomLeftRadius="18dp"
        android:bottomRightRadius="18dp" />
    <solid android:color="@color/black" />
</shape>
<com.github.siyamed.shapeimageview.RoundedImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/neo"
    app:siRadius="6dp"
    app:siBorderWidth="6dp"
    app:siBorderColor="@color/darkgray"
    app:siSquare="true"/>