Android 控件模糊案例
来源:互联网 发布:做淘宝货源哪里找 编辑:程序博客网 时间:2024/06/03 17:15
blurkit-android
BlurKit is an extraordinarily easy to use utility to get live blurring just like on iOS. Built by Dylan McIntyre.
BlurKit is faster than other blurring libraries due to a number of bitmap retrieval and drawing optimizations. We've been logging benchmarks for the basic high-intensity tasks for a 300dp x 100dp BlurView:
This results in an average work/frame time of 2-4ms, which will be a seamless experience for most users and apps.
Setup
Add BlurKit to your dependencies block:
compile 'com.wonderkiln:blurkit:1.0.0'
You also need to add RenderScript to your app module. Add these lines to the defaultConfig
block of yourbuild.gradle.
renderscriptTargetApi 24renderscriptSupportModeEnabled true
Usage
BlurLayout
Add a BlurLayout
to your layout just like any other view.
<com.wonderkiln.blurkit.BlurLayout android:id="@+id/blurLayout" android:layout_width="150dp" android:layout_height="150dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="BlurKit!" android:textColor="@android:color/white" /></com.wonderkiln.blurkit.BlurLayout>
The layout background will continuously blur the content behind it. If you know your background content will be somewhat static, you can set the layout fps
to 0
. At any time you can re-blur the background content by callinginvalidate()
on the BlurLayout
.
<com.wonderkiln.blurkit.BlurLayout xmlns:blurkit="http://schemas.android.com/apk/res-auto" android:id="@+id/blurLayout" android:layout_width="150dp" android:layout_height="150dp" blurkit:blk_fps="0" />
Other attributes you can configure are the blur radius and the downscale factor. Getting these to work together well can take some experimentation. The downscale factor is a performance optimization; the bitmap for the background content will be downsized by this factor before being drawn and blurred.
<com.wonderkiln.blurkit.BlurLayout xmlns:blurkit="http://schemas.android.com/apk/res-auto" android:id="@+id/blurLayout" android:layout_width="150dp" android:layout_height="150dp" blurkit:blk_blurRadius="12" blurkit:blk_downscaleFactor="0.12" blurkit:blk_fps="60" />
Other
You can use the BlurKit
class which has a few useful blurring utilities. Before using this class outside of aBlurLayout
, you need to initialize BlurKit
.
public class MyApplication extends Application { @Override public void onCreate() { BlurKit.init(this); }}
You can blur a View
, or a Bitmap
directly.
// ViewBlurKit.getInstance().blur(View src, int radius);// BitmapBlurKit.getInstance().blur(Bitmap src, int radius);
You can also fastBlur a View
. This optimizes the view blurring process by allocating a downsized bitmap and using a Matrix
with the bitmaps Canvas
to prescale the drawing of the view to the bitmap.
BlurKit.getInstance().fastBlur(View src, int radius, float downscaleFactor);
Proguard
If you use Proguard, add the following to your proguard-rules.pro:
-keep class com.wonderkiln.blurkit.** { *; }-dontwarn android.support.v8.renderscript.*-keepclassmembers class android.support.v8.renderscript.RenderScript { native *** rsn*(...); native *** n*(...);}
To Do (incoming!)
- [ ]
SurfaceView
support - [ ] Support for use outside of an
Activity
(dialogs, etc.) - [ ] Enhance retrieval of background content to only include views drawn behind the
BlurLayout
.
Credits
Dylan McIntyre
License
BlurKit-Android is MIT licensed.
- Android 控件模糊案例
- Android小控件之模糊匹配
- sql 模糊查询案例!
- Android侧滑控件DrawerLayout实战案例
- Android自定义控件系列案例【一】
- Android自定义控件系列案例【二】
- Android自定义控件系列案例【三】
- Android自定义控件系列案例【四】
- Android自定义控件系列案例【五】
- Android ToggleButton,Switch控件完整案例
- Android控件显示和隐藏案例详解
- Android中修改源码实现AutoCompeteTextView控件的模糊匹配
- Android中修改源码实现AutoCompeteTextView控件的模糊匹配
- Android中修改源码实现AutoCompeteTextView控件的模糊匹配
- Android之控件阴影模糊效果死磕Paint.setShadowLayer()
- Android控件ListView和Spinner组合控件案例
- android开发------案例四(带有控件的ListView)
- 【Android UI】案例04配置控件点击效果(selector)
- 关于类似朋友圈的发布时间间隔计算问题(python)
- 前序遍历
- oracle中常用的sql语句--基本语句
- 手机、电话号码、邮箱、域名、身份证号的测试用例
- 求解一元二次方程
- Android 控件模糊案例
- Windows性能监视器数值分析(转)
- TCP/UDP
- String、StringBuffer与StringBuilder之间区别
- 巧用代码
- vue.js学习笔记-11
- Java RMI架构(远程方法调用)
- Spring介绍
- google 手机号码校验库libphonenumber