邯郸网站设计价格,做网站哪便宜,珠海网站设计培训学校,品牌购买网站Android 实现圆角图片的简单实例实现效果图#xff1a;本来想在网上找个圆角的例子看一看#xff0c;不尽人意啊#xff0c;基本都是官方的Demo的那张原理图#xff0c;稍后会贴出。于是自己自定义了个View#xff0c;实现图片的圆角以及圆形效果。效果图#xff1a;Andr…Android 实现圆角图片的简单实例实现效果图本来想在网上找个圆角的例子看一看不尽人意啊基本都是官方的Demo的那张原理图稍后会贴出。于是自己自定义了个View实现图片的圆角以及圆形效果。效果图Android 圆角图片的实现形式包括用第三方、也有系统的。比如makeramen:roundedimageview系统的cardview glide .fresco 。compile com.android.support:appcompat-v7:24.0.0compile com.makeramen:roundedimageview:2.2.1compile com.android.support:cardview-v7:24.0.0compile com.github.bumptech.glide:glide:3.7.0compile com.facebook.fresco:fresco:0.12.0xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoandroid:idid/id_cardviewandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_gravitycenter_horizontalapp:cardBackgroundColorcolor/bg_light_grayapp:cardCornerRadius3dpapp:cardUseCompatPaddingfalseapp:cardPreventCornerOverlaptrueandroid:idid/iv_subjectandroid:gravitycenterandroid:scaleTypecenterCropandroid:layout_widthmatch_parentandroid:layout_height200dp /android:paddingLeft5dpandroid:paddingBottom5dpandroid:backgrounddrawable/bg_biaotiandroid:idid/tv_subjectandroid:gravitycenter_verticalandroid:textandroid:ellipsizeendandroid:singleLinetrueandroid:textSize13spandroid:textColorcolor/whiteandroid:layout_gravitybottomandroid:layout_widthmatch_parentandroid:layout_heightwrap_content /iv_round(RoundedImageView) findViewById(R.id.iv_round);Glide.with(this).load(url).into(iv_round);iv_cardview(ImageView)findViewById(R.id.iv_cardview);Glide.with(this).load(url).into(iv_cardview);iv_fresco(SimpleDraweeView)findViewById(R.id.iv_fresco);Glide.with(this).load(url).into(iv_round);Glide.with(this).load(url).into(iv_cardview);Uri uri Uri.parse(url);iv_fresco.setImageURI(uri);package roundimageview.forezp.com.roundimageview;import android.content.Context;import android.content.res.Resources;import android.graphics.Bitmap;import android.graphics.BitmapShader;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.RectF;import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;/*** Created by Administrator on 2016/8/19 0019.*/public class GlideRoundTransform extends BitmapTransformation {private static float radius 0f;public GlideRoundTransform(Context context) {this(context, 4);}public GlideRoundTransform(Context context, int dp) {super(context);this.radius Resources.getSystem().getDisplayMetrics().density * dp;}Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {return roundCrop(pool, toTransform);}private static Bitmap roundCrop(BitmapPool pool, Bitmap source) {if (source null) return null;Bitmap result pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);if (result null) {result Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);}Canvas canvas new Canvas(result);Paint paint new Paint();paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));paint.setAntiAlias(true);RectF rectF new RectF(0f, 0f, source.getWidth(), source.getHeight());canvas.drawRoundRect(rectF, radius, radius, paint);return result;}Override public String getId() {return getClass().getName() Math.round(radius);}}Glide.with(this).load(url).transform(new GlideRoundTransform(this,6)).into(iv_glide);感谢阅读希望能帮助到大家谢谢大家对本站的支持