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"
/>