安卓android webview圆角效果
来源:互联网 发布:linux查看mysql的密码 编辑:程序博客网 时间:2024/05/21 22:43
一开始使用shape的方式实现,发现不行,网页出来以后就会填充满
后来使用搜索引擎,看到其他人实现的webview圆角效果,连接 http://blog.csdn.net/zxwd2015/article/details/64554653
实测,性能太差,卡顿明显
于是自己重写
看了下他的代码,搞了4个path,各种moveTo和lineTo,我就想能不能把4个path合成1个path
或者能不能找到一个函数可以搞定的,找到了addRoundRect函数
呃,这就很舒服
链接:
http://www.cnblogs.com/everhad/p/6161083.html
http://blog.csdn.net/qiushi_1990/article/details/53188554
所以,自己改了下他们的代码
完整代码如下:
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
/** * 圆角webview */public class CornersWebView extends WebView { private float top_left = 0; private float top_right = 0; private float bottom_left = 0; private float bottom_right = 0; private int vWidth; private int vHeight; private int x; private int y; private Paint paint1; private Paint paint2; private float[] radiusArray = {0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f}; public CornersWebView(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); } public CornersWebView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context, attrs); } private void init(Context context, AttributeSet attrs) { paint1 = new Paint(); paint1.setColor(Color.WHITE); paint1.setAntiAlias(true); paint1.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); paint2 = new Paint(); paint2.setXfermode(null); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.cornersWebView); // 读取xml styleable,attrs是xml属性的集合 top_left = a.getDimension(R.styleable.cornersWebView_top_left, 0); top_right = a.getDimension(R.styleable.cornersWebView_top_right, 0); bottom_left = a.getDimension(R.styleable.cornersWebView_bottom_left, 0); bottom_right = a.getDimension(R.styleable.cornersWebView_bottom_right, 0); setRadius(top_left, top_right, bottom_right, bottom_left); } /** * 设置四个角的圆角半径 */ public void setRadius(float leftTop, float rightTop, float rightBottom, float leftBottom) { radiusArray[0] = leftTop; radiusArray[1] = leftTop; radiusArray[2] = rightTop; radiusArray[3] = rightTop; radiusArray[4] = rightBottom; radiusArray[5] = rightBottom; radiusArray[6] = leftBottom; radiusArray[7] = leftBottom; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); vWidth = getMeasuredWidth(); vHeight = getMeasuredHeight(); } @Override public void onDraw(Canvas canvas) { Log.e("jiejing", "onDraw"); x = this.getScrollX(); y = this.getScrollY(); Path path = new Path(); path.addRoundRect(new RectF(0, y, x + vWidth, y + vHeight), radiusArray, Path.Direction.CW); // 使用半角的方式,性能比较好 canvas.clipPath(path); super.onDraw(canvas); }}
注意:
cavas.clipPath不支持硬件加速,记得在AndroidManifest.xml中设置不使用硬件加速。不然效果出不来
或者myView.setLayerType(View.LAYER_TYPE_HARDWARE, null);关闭硬件加速
阅读全文
0 0
- 安卓android webview圆角效果
- Android(安卓)WebView设置cookie
- 安卓笔记android WebView乱码解决办法
- Android安卓WebView下载文件问题
- 安卓WebView介绍
- 安卓开发webview
- 安卓WebView
- 安卓WebView使用
- 安卓webview
- 安卓学习-WebView
- 【Android】安卓学习笔记之使用WebView加载网页
- 安卓Android WebView 加载H5的解决问题
- android WebView界面切换效果
- android webview实现进度条效果
- android webview实现加载效果
- 安卓webview禁止滚动
- 安卓:WebView简单使用
- 安卓webView,js交互
- Introduction to D3
- ViewDragHelper
- eclipse编译安卓时报错
- 1021. 个位数统计 (15)
- sql 语法篇2
- 安卓android webview圆角效果
- 什么是HTML
- NLMS算法简介及基于NLMS的时域EC实现
- Android体系结构
- 近期海投笔试遇到的问题(3)
- MySQL5.7 四种日志文件
- ubuntu下ctags安装和使用
- require.js
- 课程设计---图书登记管理系统