1、上边圆角图片
第一种方式
自定义控件:
public class TopCornerImageView extends AppCompatImageView { //圆角弧度 private float[] rids = {10.0f,10.0f,10.0f,10.0f,0.0f,0.0f,0.0f,0.0f,}; public TopCornerImageView(Context context) { super(context); } public TopCornerImageView(Context context, AttributeSet attrs) { super(context, attrs); } public TopCornerImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } protected void onDraw(Canvas canvas) { Path path = new Path(); int w = this.getWidth(); int h = this.getHeight(); //绘制圆角imageview path.addRoundRect(new RectF(0,0,w,h),rids,Path.Direction.CW); canvas.clipPath(path); super.onDraw(canvas); } }
xml:
<com.chinaso.so.widget.TopCornerImageView
android:id="@+id/iv_image"
android:layout_width="113dp"
android:layout_height="150dp"
android:scaleType="fitXY"
android:src="@mipmap/icon_default_pic"/>
代码:
ImageView imageView1 = helper.getView(R.id.iv_image);
GlideApp
.with(mContext)
.load(item.getIconsrc())
.error(R.mipmap.icon_default_small)
.placeholder(R.mipmap.icon_default_small)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(imageView1);
第二种方式
转载:https://blog.csdn.net/cccrunner/article/details/72594703
添加依赖
控件属性:
riv_border_width: 边框宽度
riv_border_color: 边框颜色
riv_oval: 是否圆形
riv_corner_radius: 圆角弧度
riv_corner_radius_top_left:左上角弧度
riv_corner_radius_top_right: 右上角弧度
riv_corner_radius_bottom_left:左下角弧度
riv_corner_radius_bottom_right:右下角弧度
xml:
<com.makeramen.roundedimageview.RoundedImageView android:id="@+id/iv_image" android:layout_width="113dp" android:layout_height="150dp" android:scaleType="fitXY" android:src="@mipmap/icon_default_pic" app:riv_corner_radius_top_left="4dp" app:riv_corner_radius_top_right="4dp" app:riv_oval="false" />
代码:
ImageView imageView1 = helper.getView(R.id.iv_image);
GlideApp
.with(mContext)
.load(item.getIconsrc())
.error(R.mipmap.icon_default_small)
.placeholder(R.mipmap.icon_default_small)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(imageView1);