Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案
Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案
RoundedBitmapDrawable是Android在support v4的扩展包中新增的实现圆角图形的关键类,借助RoundedBitmapDrawable的帮助,可以轻松的以Android标准方式实现圆角图形图象。
写一个简单的例子。
写一个线性布局,竖直方向放三个ImageView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="zhangphil.app.MainActivity"> <ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" /> <ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" /> <ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" /> </LinearLayout>
然后通过Java代码分别放原始图,圆角图,圆形图作为对比:
package zhangphil.app; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //未做圆角处理的原始图
ImageView image1 = (ImageView) findViewById(R.id.imageView1);
image1.setImageResource(R.drawable.zhangphil); //圆角图
RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.zhangphil));
roundedDrawable.getPaint().setAntiAlias(true);
roundedDrawable.setCornerRadius(30);
ImageView image2 = (ImageView) findViewById(R.id.imageView2);
image2.setImageDrawable(roundedDrawable); //圆形图
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.zhangphil);
RoundedBitmapDrawable circleDrawable = RoundedBitmapDrawableFactory.create(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.zhangphil));
circleDrawable.getPaint().setAntiAlias(true);
circleDrawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()));
ImageView image3 = (ImageView) findViewById(R.id.imageView3);
image3.setImageDrawable(circleDrawable);
}
}
代码运行结果:
附录文章:
1,《Android圆形头像图Circle ImageView》链接地址:http://blog.csdn.net/zhangphil/article/details/44960551
2,《Android CustomShapeImageView对图片进行各种样式裁剪:圆形、星形、心形、花瓣形等》链接地址:http://blog.csdn.net/zhangphil/article/details/50119921
Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案的更多相关文章
- Android 正 N 边形圆角头像的实现
卖一下广告,欢迎大家关注我的微信公众号,扫一扫下方二维码或搜索微信号 stormjun94(徐公码字),即可关注. 目前专注于 Android 开发,主要分享 Android开发相关知识和一些相关的优 ...
- 解决Android微信支付官方demo运行失败
Android微信支付官方demo运行失败,在此简单记录一下解决步骤 1.httpclient错误 官方给的demo是eclipse的,打开之后提示httpclient的错误,我知道在as下解决htt ...
- Android一个炫酷的树状图组织架构图开源控件实现过程
Android一个炫酷的树状图组织架构图开源控件 文章目录 [1 简介] [2 效果展示] [3 使用步骤] [4 实现基本布局流程] [5 实现自由放缩及拖动] [6 实现添加删除及节点动画] [7 ...
- Android 中shape的使用(圆角矩形)
一.在res/drawable文件夹下创建一个名为gradient_box的xml文件: <?xml version="1.0" encoding="utf-8&q ...
- 蓝牙4.0——Android BLE开发官方文档翻译
ble4.0开发整理资料_百度文库 http://wenku.baidu.com/link?url=ZYix8_obOT37JUQyFv-t9Y0Sv7SPCIfmc5QwjW-aifxA8WJ4iW ...
- Android中实现控件圆角边框
首先,在drawable文件夹下新建一个xml文件: <?xml version="1.0" encoding="utf-8"?> <shap ...
- 【Android】Android布局中实现圆角边框
设置corners_bg.xml 设置边框圆角可以在drawable-mdpi目录里定义一个xml: <?xml version="1.0" encoding="u ...
- android ndk调用OpenGL 实现纹理贴图Texture
android ndk调用OpenGL 实现纹理贴图Texture 时间 2014-06-25 05:24:39 CSDN博客 原文 http://blog.csdn.net/chrisfxs/a ...
- Android图表库MPAndroidChart(八)——饼状图的扩展:折线饼状图
Android图表库MPAndroidChart(八)--饼状图的扩展:折线饼状图 我们接着上文,饼状图的扩展,增加折现的说明,来看下我们要实现的效果 因为之前对MPAndroidChart的熟悉,所 ...
随机推荐
- Saas物联网共享平台实战
什么是SaaS系统: 越来越多的软件,开始采用云服务. 云服务只是一个统称,可以分成三大类. IaaS:基础设施服务,Infrastructure-as-a-service PaaS:平台服务,Pla ...
- js 宿主对象的属性和方法总结
(1)属性: //height,width; a=document.documentElement.clientHeight; //文档可视高度,由 ...
- 移动端rem
手机有很多尺寸的型号.使用rem来做为大小单位可以达到兼容的目的. 方法一:js测量手机尺寸,设置font-size:为手机屏幕width /10 + ‘px’.即10rem 为手机屏幕width. ...
- 10.3 Implementing pointers and objects and 10.4 Representing rooted trees
Algorithms 10.3 Implementing pointers and objects and 10.4 Representing rooted trees Allocating an ...
- 镜像中的 Everything, GnomeLive ,KdeLive ,livecd ,NetInstall的区别?
everything: 对完整版安装盘的软件进行补充,集成所有软件 GnomeLive , GNOME桌面版 KdeLive , KDE桌面版 livecd 光盘上运行的系统 ,NetInstall ...
- 快速开发框架天梭(Tissot)
天梭(Tissot)集成SpringBoot+Dubbo等主流互联网技术栈,高度集成.优化方便快速搭建应用.某互金科技公司内部孵化框架,已应用于公司90%业务系统. 框架划分模块有: tissot-c ...
- SQL Server中行列转置方法
PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P ...
- Node.js——npm
npm un 包名 :删除指定包,不删除安装的依赖 npm un --save 包名: 删除包,并且删除其依赖项 npm install -g cnpm --registry=https://regi ...
- Zookeeper系列(一)
一.ZooKeeper的背景 1.1 认识ZooKeeper ZooKeeper---译名为“动物园管理员”.动物园里当然有好多的动物,游客可以根据动物园提供的向导图到不同的场馆观赏各种类型的动物,而 ...
- 【git】搭建git服务器
在 Linux 下搭建 Git 服务器 目录 ① 安装 Git ② 服务器端创建 git 用户,用来管理 Git 服务,并为 git 用户设置密码 ③ 服务器端创建 Git 仓库 ④ 客户端 clon ...