Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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
Android 图像角半径_Android_Xml - Fatal编程技术网

Android 图像角半径

Android 图像角半径,android,xml,Android,Xml,有没有办法通过xml布局来绕过ImageView?即使没有,我们可以通过什么方式实现这一目标 注:正在从API获取图像URL。不是从可绘制的文件夹可以使用如下自定义视图实现 public class RoundImageView extends ImageView { private float mRadius = 18.0f; private Path mPath; private RectF mRect; public RoundImageView(Con

有没有办法通过
xml布局来绕过
ImageView
?即使没有,我们可以通过什么方式实现这一目标


注:正在从API获取
图像URL
。不是从
可绘制的
文件夹

可以使用如下自定义视图实现

public class RoundImageView extends ImageView {

    private float mRadius = 18.0f;
    private Path mPath;
    private RectF mRect;

    public RoundImageView(Context context) {
        super(context);
        init();
    }

    public RoundImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public RoundImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        mPath = new Path();

    }

    @Override
    protected void onDraw(Canvas canvas) {
        mRect = new RectF(0, 0, this.getWidth(), this.getHeight());

        mPath.addRoundRect(mRect, mRadius, mRadius, Path.Direction.CW);

        canvas.clipPath(mPath);

        super.onDraw(canvas);
    }
}
并在XML中使用它

<your_pkag.RoundImageView
     android:id="@+id/imgView"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:src="@drawable/image" />

使用

使用


我不知道你想做什么。但是对于边界

您可以创建如下所示的可绘制文件

line.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="5dp" />
    <stroke android:width="2dp" android:color="#000" />
</shape>
    <ImageView
        android:layout_height:"200dp"
        android:layout_width:"200dp"
        android:background:"@drawable/line.xml"
    />

尝试此链接中的示例:java文件RoundImageView如何在xml中使用的可能重复?像这样
同样,我从我的api中获取图像,因此
android:background=“@drawable/image”
将不起作用?或者可以吗?因为图像URL来自API,我在ImageView中设置了它。因此,我认为不可能将其设置为背景。删除
android:background=“@drawable/image”
并使用
android:src=“@drawable/image”
。我更新了我的答案好的。谢谢,我会试试的。所以你用的是api,我用的是毕加索。可以这样做吗?否则我就用滑翔。不管怎样,这已经在我脑海中出现了一段时间了,我应该使用毕加索还是Glide
    <ImageView
        android:layout_height:"200dp"
        android:layout_width:"200dp"
        android:background:"@drawable/line.xml"
    />