安卓imageview实现上面两个圆角下面两个直角的效果
来源:互联网 发布:linux cp文件夹 编辑:程序博客网 时间:2024/04/28 21:52
由于产品奇葩要求要求实现下面效果,奇葩的地方就在,要求图片上面两个是圆角,下面两个是直接。
自己研究了半天找出来了下面两种解决方案
一,用自定义imageview
import android.content.Context;import android.graphics.Canvas;import android.graphics.Path;import android.graphics.RectF;import android.util.AttributeSet;import android.widget.ImageView;/**用来显示不规则图片,* 上面两个是圆角,下面两个是直角* */public class OvalImageView extends ImageView { /*圆角的半径,依次为左上角xy半径,右上角,右下角,左下角*/ private float[] rids = {10.0f, 10.0f, 10.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f,}; public OvalImageView(Context context) { super(context); } public OvalImageView(Context context, AttributeSet attrs) { super(context, attrs); } public OvalImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } /** * 画图 * by Hankkin at:2015-08-30 21:15:53 * * @param canvas */ protected void onDraw(Canvas canvas) { Path path = new Path(); int w = this.getWidth(); int h = this.getHeight(); /*向路径中添加圆角矩形。radii数组定义圆角矩形的四个圆角的x,y半径。radii长度必须为8*/ path.addRoundRect(new RectF(0, 0, w, h), rids, Path.Direction.CW); canvas.clipPath(path); super.onDraw(canvas); }}
二,借助glide(glide是一个图片加载库,很强大,大家自己了解怎么使用,使用起来也很简单)
//上面两个圆角,下面两个直角 Glide.with(this) .load(images2) // .bitmapTransform(new GrayscaleTransformation(this))//带灰色蒙层 .bitmapTransform(new RoundedCornersTransformation(this, 60, 0, RoundedCornersTransformation.CornerType.TOP)) .into(image3);//下面两个圆角,上面两个直角 Glide.with(this) .load(images2) // .bitmapTransform(new GrayscaleTransformation(this))//带灰色蒙层 .bitmapTransform(new RoundedCornersTransformation(this, 60, 0, RoundedCornersTransformation.CornerType.BOTTOM)) .into(image3);注:glide可以实现圆角图片,右边两个圆角左边两个直角等奇葩得效果
0 2
- 安卓imageview实现上面两个圆角下面两个直角的效果
- Android实现Imageview上面圆角下面直角效果
- 安卓自定义上面圆角下面直角的RoundCornerImageView
- android上面圆角,下面直角 ImageView
- Android 自定义上面圆角下面直角的ImageView
- android ImageView实现上面圆角下面直角(xml实现方法)
- android ImageView实现上面圆角下面直角(自定义view实现)
- 实现Imageview两个圆角的效果
- 实现上面两个角和下面两个角不同的xml drawable
- 设置Button按钮上面圆角下面直角
- bitmap 上面两个圆角
- 安卓实现两个Tablehost的嵌套
- .net下实现鼠标左右两个按键齐击,就好像扫雷下面的效果
- 视图的上面两个角有弧度
- Imageview上边圆角,下边直角
- 设置imageView顶部两个圆角
- Python实现“已知三角形两个直角边,求斜边”
- 安卓第四天————利用两个activity实现切换效果
- 浏览器内部工作原理
- java设计模式之工厂方法设计模式
- 如何实现基于内容和用户画像的个性化推荐
- 16 - 11 - 16 二叉树(C)生成之--终极奥义--书上没讲的!!
- could not delete: [org.jbpm.pvm.internal.model.ExecutionImpl#20007] 使用jbpm流程结束时出现异常
- 安卓imageview实现上面两个圆角下面两个直角的效果
- 1116学习记录 右下角悬浮框
- faster rcnn源码理解
- 【codevs 1540】银河英雄传说2002年NOI全国竞赛(并查集)
- 约瑟夫环问题
- FileReader读取文件
- Android使用Retrofit上传图片到服务器
- openH264 1.6下安卓编译
- shmvc之test