android 简单实现圆角,Android 实现圆角图片的简单实例

Android 实现圆角图片的简单实例

实现效果图:

61e5c5f9da31a27a88cbdca7bd5c50d3.png

本来想在网上找个圆角的例子看一看,不尽人意啊,基本都是官方的Demo的那张原理图,稍后会贴出。于是自己自定义了个View,实现图片的圆角以及圆形效果。效果图:

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'

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"

>

android:id="@+id/iv_subject"

android:gravity="center"

android:scaleType="centerCrop"

android:layout_width="match_parent"

android:layout_height="200dp" />

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" />

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);

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/394677.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

zookeeper介绍及集群的搭建(利用虚拟机)

ZooKeeper ​   ZooKeeper是一个分布式的,开放源码(apache)的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase、dubbox、kafka的重要组件。它主要用来解决分布式集群中应用系统的一致性问题…

pythondict初始化_利用defaultdict对字典进行全局初始化。

通常我们在操作字典时,如果读取的键未被初始化,则会抛出KeyError的错误,这个是我们都很熟悉的。那么一般的解决方式是使用异常处理或者是调用字典的get方法来避免出现这个异常。 可以看到,这两种写法都比较繁琐,第二种…

标准库类型String

定义和初始化string对象 初始化string对象方式 string s1 默认初始化,s1是一个空串 string s2(s1) s2是s1的副本 string s2 s1 等价于s2(s1), s2是s1的副本 string s3("value") s3是字面值"value"的副本,除了字面值最后的那个…

轻量级数据库中间件利器Sharding-JDBC深度解析(有彩蛋)

讲师介绍张亮 当当架构部总监 负责分布式中间件和私有云平台建设 目前主导开源项目:Elastic-Job及Sharding-JDBC 主题简介: 1、关系型数据库中间件核心功能介绍 2、Sharding-JDBC架构及内核解析 3、Sharding-JDBC未来展望 一、关系型数据库中间件核心功…

python字典嵌套字典的情况下获取某个key的value

最近在用python写接口的测试程序,期间用到解析字典获取某个key的value,由于多个接口返回的字典格式不是固定的并存在多层嵌套的情况。在字典的方法中也没有找到可直接达到目的的方法(也可能是我对字典的方法了解的不深的缘故),于是自己写了个…

系统在此应用程序堆栈溢出_从部署我的第一个完整堆栈Web应用程序中学到的经验教训...

系统在此应用程序堆栈溢出by Will Abramson威尔艾布拉姆森(Will Abramson) 从部署我的第一个完整堆栈Web应用程序中学到的经验教训 (Lessons learned from deploying my first full-stack web application) I recently achieved one of my long-term goals: deploying my firs…

const 常量_条款03:尽可能使用const

const 允许你指定一个语义约束(也就是指定一个“不该被改动”的对象),而编译器会强制实施这项约束。1、const指针如果关键字const出现在星号左边,表示被指物是常量;如果出现在星号右边,表示指针自身是常量&…

javascript高级程序设计---js事件思维导图

绘制思维软件与平时用的笔记,以及导出功能,这三个问题综合起来,于是我把思维导图分开画 1、js事件的基本概念 2、js事件的事件处理程序 3、js事件的事件对象 转载于:https://www.cnblogs.com/Jamie1032797633/p/10567419.html

jq挑战30天——打字机效果+小程序

<!doctype html><html><head><meta charset"utf-8"><title>基于jQuery实现的打字机效果-jq22.com</title><script src"http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script><style></…

和 Thrift 的一场美丽邂逅

一. 与 Thrift 的初识 也许大多数人接触 Thrift 是从序列化开始的。每次搜索 “java序列化” “方式”、“对比” 或 “性能” 等关键字时&#xff0c;搜索引擎总是会返回一大堆有关各种序列化方式的使用方法或者性能对比的结果给你&#xff0c;而其中必定少不了 Thrift&#…

instagram技术_Instagram9位科技女孩进行技术采访的主要技巧

instagram技术by Rachel通过瑞秋 Instagram9位科技女孩进行技术采访的主要技巧 (Top tips for technical interviews from nine of Instagram’s tech girls) My job-hunt came to an end a few weeks ago. After endless phone interviews, coding challenges, and on-sites,…

弹出框 每次打开 滚动条置顶_微信置顶文字怎么弄?微信置顶一句话教程

今日支付宝红包支付宝首页搜索511501453马上领取红包(支付宝双十二活动&#xff0c;瓜分15亿红包)(领取后一定要记得使用&#xff0c;不然会浪费的呦&#xff0c;更会影响第二天的领取&#xff01;)奶思靓机“ 一 个 有 用 的 公 众 号 の ”嗨&#xff0c;最近很流行在微信上面…

Python学习_字符串格式化

#!/usr/bin/env python # -*- coding:utf-8 -*-# 百分号格式化 # %[(name)[flags][width].[precision]]typecode # name : 指定占位符的key # flags : - 空格 0 # width : 宽度 # precision : 小数点后保留的位数 # typecode : 必需,数据类型 # 字符串里面有%的时候, %%表示一…

python 3 面向过程编程

python 3 面向过程编程 核心是过程&#xff08;流水线式思维&#xff09;&#xff0c;过程即解决问题的步骤&#xff0c;面向过程的设计就像设计好一条工业流水线&#xff0c;是一种机械式的思维方式。 1、优点&#xff1a;程序结构清晰&#xff0c;可以把复杂的问题简单化&…

在ionic/cordova中使用百度地图插件

在ionic项目中&#xff0c;如果想实现定位功能&#xff0c;可以使用ng-cordova提供的cordova-plugin-geolocation。 但由于高墙的缘故&#xff0c;国内andorid环境下&#xff0c;此插件不起作用&#xff08;ios环境下可用&#xff09;。 国内比较好的是现实使用百度地图提供的A…

django国际化与html语言,Django 国际化

Django 国际化Django 支持国际化&#xff0c;多语言。Django的国际化是默认开启的&#xff0c;如果您不需要国际化支持&#xff0c;那么您可以在您的设置文件中设置 USE_I18N False&#xff0c;那么Django会进行一些优化&#xff0c;不加载国际化支持机制。NOTE: 18表示Intern…

mongo 删除节点_将生产节点/ Express Mongo App部署到AWS —反思

mongo 删除节点在AWS中部署生产Web应用程序的经验教训 (Lessons learned deploying a production web application in AWS) 背景 (Background) This is not a code-based tutorial. It consists of all the things I wish I knew before I started the project and the steps I…

汉诺塔问题递归算法python代码_[python]汉诺塔问题递归实现

一、问题描述及算法步骤 汉诺塔问题的大意是有三根柱子a, b, c&#xff0c;现在a柱有N个盘子从下往上尺寸递减排列&#xff0c;要求&#xff1a; 1. 将a上的盘子移动到c柱上; 2. 每次移动一个盘子; 3. 柱子上的盘子始终必须是大的在下面image.png 汉诺塔问题的经典实现算法步骤…

【硬件】PCB设计步骤

前言 合理的PCB设计步骤&#xff0c;可以减少反复修改的可能性。动手设计PCB前&#xff0c;需要按步就班准备一些资料&#xff0c;即使是小项目。 本文将讲解如何一次性成功地设计一款PCB的常规步骤。 当然&#xff0c;如果是一个系统&#xff0c;则需要按照瀑布式的思路&#…

linux install StarDict

1.  sudo apt-get install stardict 2.  Downloads from: http://abloz.com/huzheng/stardict-dic/zh_CN/ 3.  tar jxf stardict-21shijishuangxiangcidian-2.4.2.tar.bz2 -C /usr/share/stardict/dic (etc other dictionaries)转载于:https://www.cnblogs.com/HurryXin/…