android 圆角图片的实现形式,包括用第三方、也有系统的。比如makeramen:roundedimageview,系统的cardview , glide .fresco 。

  1. compile 'com.android.support:appcompat-v7:24.0.0'
  2. compile 'com.makeramen:roundedimageview:2.2.1'
  3. compile 'com.android.support:cardview-v7:24.0.0'
  4. compile 'com.github.bumptech.glide:glide:3.7.0'
  5. compile 'com.facebook.fresco:fresco:0.12.0'
  1. <android.support.v7.widget.CardView
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. android:id="@+id/id_cardview"
  5. android:layout_width="match_parent"
  6. android:layout_height="wrap_content"
  7. android:layout_gravity="center_horizontal"
  8. app:cardBackgroundColor="@color/bg_light_gray"
  9. app:cardCornerRadius="3dp"
  10. app:cardUseCompatPadding="false"
  11. app:cardPreventCornerOverlap="true"
  12. >
  13. <ImageView
  14. android:id="@+id/iv_subject"
  15. android:gravity="center"
  16. android:scaleType="centerCrop"
  17. android:layout_width="match_parent"
  18. android:layout_height="200dp" />
  19. <TextView
  20. android:paddingLeft="5dp"
  21. android:paddingBottom="5dp"
  22. android:background="@drawable/bg_biaoti"
  23. android:id="@+id/tv_subject"
  24. android:gravity="center_vertical"
  25. android:text=""
  26. android:ellipsize="end"
  27. android:singleLine="true"
  28. android:textSize="13sp"
  29. android:textColor="@color/white"
  30. android:layout_gravity="bottom"
  31. android:layout_width="match_parent"
  32. android:layout_height="wrap_content" />
  33. </android.support.v7.widget.CardView>

  1. iv_round=(RoundedImageView) findViewById(R.id.iv_round);
  2. Glide.with(this).load(url).into(iv_round);
  1. iv_cardview=(ImageView)findViewById(R.id.iv_cardview);
  2. Glide.with(this).load(url).into(iv_cardview);
  1. iv_fresco=(SimpleDraweeView)findViewById(R.id.iv_fresco);
  2. Glide.with(this).load(url).into(iv_round);
  3. Glide.with(this).load(url).into(iv_cardview);
  4. Uri uri = Uri.parse(url);
  5. iv_fresco.setImageURI(uri);
  1. package roundimageview.forezp.com.roundimageview;
  2. import android.content.Context;
  3. import android.content.res.Resources;
  4. import android.graphics.Bitmap;
  5. import android.graphics.BitmapShader;
  6. import android.graphics.Canvas;
  7. import android.graphics.Paint;
  8. import android.graphics.RectF;
  9. import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
  10. import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
  11. /**
  12. * Created by Administrator on 2016/8/19 0019.
  13. */
  14. public class GlideRoundTransform extends BitmapTransformation {
  15. private static float radius = 0f;
  16. public GlideRoundTransform(Context context) {
  17. this(context, 4);
  18. }
  19. public GlideRoundTransform(Context context, int dp) {
  20. super(context);
  21. this.radius = Resources.getSystem().getDisplayMetrics().density * dp;
  22. }
  23. @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
  24. return roundCrop(pool, toTransform);
  25. }
  26. private static Bitmap roundCrop(BitmapPool pool, Bitmap source) {
  27. if (source == null) return null;
  28. Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
  29. if (result == null) {
  30. result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
  31. }
  32. Canvas canvas = new Canvas(result);
  33. Paint paint = new Paint();
  34. paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
  35. paint.setAntiAlias(true);
  36. RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
  37. canvas.drawRoundRect(rectF, radius, radius, paint);
  38. return result;
  39. }
  40. @Override public String getId() {
  41. return getClass().getName() + Math.round(radius);
  42. }
  43. }
  1. Glide.with(this).load(url).transform(new GlideRoundTransform(this,6)).into(iv_glide);

android 圆角图片的实现形式的更多相关文章

  1. Android圆角图片汇总

    今天来对图片的圆角处理做一个简单小结,很多app里面都有圆角效果,根据不同的场景可以采用不同的方案,目前来说有三种方案是比较常用的 方案一 .9.png 应用场景:1.目标图片已知:2.针对布局背景; ...

  2. android 圆角图片的实现

    图片展示的时候总觉的直角的图片不好看?好办法来了!-- public class ToRoundCorner extends Activity{ public Bitmap toRoundCorner ...

  3. Android BitmapShader 实战 实现圆形、圆角图片

    转载自:http://blog.csdn.net/lmj623565791/article/details/41967509 1.概述 记得初学那会写过一篇博客Android 完美实现图片圆角和圆形( ...

  4. Android实现圆形圆角图片

    本文主要使用两种方法实现图形圆角图片 自定View加上使用Xfermode实现 Shader实现 自定View加上使用Xfermode实现 /** * 根据原图和变长绘制圆形图片 * * @param ...

  5. Android 高级UI设计笔记18:实现圆角图片

    1. 下面我们经常在APP中看到的圆角图片,如下: 再比如:微信聊天会话列表的头像是圆角的. 2. 下面分析一个Github的经典: (1)Github库地址: https://github.com/ ...

  6. Android Xfermode 实战 实现圆形、圆角图片

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/42094215,本文出自:[张鸿洋的博客] 1.概述 其实这篇本来准备Androi ...

  7. Android Imageview 图片居左居右,自定义圆角

    android:scaleType="fitStart"    图片靠左不变形显示, android:scaleType=”fitEnd”  图片靠右显示,不变形. 半透明andr ...

  8. 【转】Android BitmapShader 实战 实现圆形、圆角图片

    转载自:http://blog.csdn.net/lmj623565791/article/details/41967509 1.概述 记得初学那会写过一篇博客Android 完美实现图片圆角和圆形( ...

  9. Android 圆形/圆角图片的方法

    Android 圆形/圆角图片的方法 眼下网上有非常多圆角图片的实例,Github上也有一些成熟的项目.之前做项目,为了稳定高效都是选用Github上的项目直接用.但这样的结束也是Android开发必 ...

随机推荐

  1. inventor安装错误

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  2. Java基础02-变量

    1.为什么要使用变量? 变量就是用来记忆数据的,它是一个记忆系统 2.什么是变量? 变量就是一个容器,用来装数据的,变量是放在内存里的. 比如:内存是酒店,变量名就是房间名,变量值就是住进房间的人 3 ...

  3. Neutron命令测试3

    1.打开Ubuntu的/etc/network/interfaces文件 .默认内容如下 auto lo iface lo inet loopback 2.如果以DHCP方式配置网卡,则改为:auto ...

  4. nginx的反向代理功能和负载均衡

    使用nginx实现反向代理 Nginx只做请求的转发,后台有多个http服务器提供服务,nginx的功能就是把请求转发给后面的服务器,决定把请求转发给谁. 1安装tomcat 在一个虚拟机上创建两个t ...

  5. SQL命令行操作

    命令行操作(mysql.exe)    0.登录  :       mysql -u root -p    1.显示数据库列表:    show databases;     2.选择数据库:     ...

  6. 一个position为fixed的div,宽高自适应,怎样让它水平垂直都在窗口居中?

    .div{ position: fixed; left: %; top: %; -webkit-transform: translate(-%, -%); transform: translate(- ...

  7. Day4下午

    不会啊. T1 找规律: 辗转相减,加速. #include<iostream> #include<cstring> #include<cstdio> #inclu ...

  8. linux常用安装命令(ubuntu)

    安装 net-tools 安装命令 sudo apt install net-tools 安装ssh sudo apt-get install openssh-server 查看是否安装成功 sudo ...

  9. carousel 插件隐藏列表中几项导致左右切换出错

    1. 一般的应用场景: 用于左右快速切换显示的列表内容,比如对员工的切换. 对于这种情况必不可少需要按照部门进行搜索,目前我的做法是首次加载所有该用户可以查看的员工列表,选择部门后又选择的隐藏掉其他不 ...

  10. intellijidea课程 intellijidea神器使用技巧 3-2 livetemplate

    创建livetemplate分组: ctrl shift a ==> live templates ==> + ==> templates group 创建livetemplate模 ...