android 圆角图片的实现形式
android 圆角图片的实现形式,包括用第三方、也有系统的。比如makeramen:roundedimageview,系统的cardview , glide .fresco 。
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.makeramen:roundedimageview:2.2.1'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.facebook.fresco:fresco:0.12.0'
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/id_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:cardBackgroundColor="@color/bg_light_gray"
app:cardCornerRadius="3dp"
app:cardUseCompatPadding="false"
app:cardPreventCornerOverlap="true"
>
<ImageView
android:id="@+id/iv_subject"
android:gravity="center"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="200dp" />
<TextView
android:paddingLeft="5dp"
android:paddingBottom="5dp"
android:background="@drawable/bg_biaoti"
android:id="@+id/tv_subject"
android:gravity="center_vertical"
android:text=""
android:ellipsize="end"
android:singleLine="true"
android:textSize="13sp"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
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);
android 圆角图片的实现形式的更多相关文章
- Android圆角图片汇总
今天来对图片的圆角处理做一个简单小结,很多app里面都有圆角效果,根据不同的场景可以采用不同的方案,目前来说有三种方案是比较常用的 方案一 .9.png 应用场景:1.目标图片已知:2.针对布局背景; ...
- android 圆角图片的实现
图片展示的时候总觉的直角的图片不好看?好办法来了!-- public class ToRoundCorner extends Activity{ public Bitmap toRoundCorner ...
- Android BitmapShader 实战 实现圆形、圆角图片
转载自:http://blog.csdn.net/lmj623565791/article/details/41967509 1.概述 记得初学那会写过一篇博客Android 完美实现图片圆角和圆形( ...
- Android实现圆形圆角图片
本文主要使用两种方法实现图形圆角图片 自定View加上使用Xfermode实现 Shader实现 自定View加上使用Xfermode实现 /** * 根据原图和变长绘制圆形图片 * * @param ...
- Android 高级UI设计笔记18:实现圆角图片
1. 下面我们经常在APP中看到的圆角图片,如下: 再比如:微信聊天会话列表的头像是圆角的. 2. 下面分析一个Github的经典: (1)Github库地址: https://github.com/ ...
- Android Xfermode 实战 实现圆形、圆角图片
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/42094215,本文出自:[张鸿洋的博客] 1.概述 其实这篇本来准备Androi ...
- Android Imageview 图片居左居右,自定义圆角
android:scaleType="fitStart" 图片靠左不变形显示, android:scaleType=”fitEnd” 图片靠右显示,不变形. 半透明andr ...
- 【转】Android BitmapShader 实战 实现圆形、圆角图片
转载自:http://blog.csdn.net/lmj623565791/article/details/41967509 1.概述 记得初学那会写过一篇博客Android 完美实现图片圆角和圆形( ...
- Android 圆形/圆角图片的方法
Android 圆形/圆角图片的方法 眼下网上有非常多圆角图片的实例,Github上也有一些成熟的项目.之前做项目,为了稳定高效都是选用Github上的项目直接用.但这样的结束也是Android开发必 ...
随机推荐
- inventor安装错误
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- Java基础02-变量
1.为什么要使用变量? 变量就是用来记忆数据的,它是一个记忆系统 2.什么是变量? 变量就是一个容器,用来装数据的,变量是放在内存里的. 比如:内存是酒店,变量名就是房间名,变量值就是住进房间的人 3 ...
- Neutron命令测试3
1.打开Ubuntu的/etc/network/interfaces文件 .默认内容如下 auto lo iface lo inet loopback 2.如果以DHCP方式配置网卡,则改为:auto ...
- nginx的反向代理功能和负载均衡
使用nginx实现反向代理 Nginx只做请求的转发,后台有多个http服务器提供服务,nginx的功能就是把请求转发给后面的服务器,决定把请求转发给谁. 1安装tomcat 在一个虚拟机上创建两个t ...
- SQL命令行操作
命令行操作(mysql.exe) 0.登录 : mysql -u root -p 1.显示数据库列表: show databases; 2.选择数据库: ...
- 一个position为fixed的div,宽高自适应,怎样让它水平垂直都在窗口居中?
.div{ position: fixed; left: %; top: %; -webkit-transform: translate(-%, -%); transform: translate(- ...
- Day4下午
不会啊. T1 找规律: 辗转相减,加速. #include<iostream> #include<cstring> #include<cstdio> #inclu ...
- linux常用安装命令(ubuntu)
安装 net-tools 安装命令 sudo apt install net-tools 安装ssh sudo apt-get install openssh-server 查看是否安装成功 sudo ...
- carousel 插件隐藏列表中几项导致左右切换出错
1. 一般的应用场景: 用于左右快速切换显示的列表内容,比如对员工的切换. 对于这种情况必不可少需要按照部门进行搜索,目前我的做法是首次加载所有该用户可以查看的员工列表,选择部门后又选择的隐藏掉其他不 ...
- intellijidea课程 intellijidea神器使用技巧 3-2 livetemplate
创建livetemplate分组: ctrl shift a ==> live templates ==> + ==> templates group 创建livetemplate模 ...