Android 毛玻璃效果实现

前段时间公司要做一个类似于慕课网APP个人界面的毛玻璃的效果,如下图所示,个人头像是从服务器获取的,找了很多资料,都没有找到简洁方便的实现方式,后来在Github上看到glide-transformations这个库,如获至宝,这个库和Glide一起使用,有很多常用的效果都可以通过它搞定,如:圆角图片等等,并且使用起来很简单,通过它毛玻璃效果可以很很轻松地实现啦,一行代码就搞定。

首先要导入两个库

compile 'com.github.bumptech.glide:glide:3.7.0'compile 'jp.wasabeef:glide-transformations:2.0.1'

布局文件:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent" android:layout_height="match_parent"    android:orientation="vertical">    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="wrap_content">        <ImageView android:id="@+id/iv_blur"            android:layout_width="match_parent"            android:layout_height="200dp" />        <ImageView android:id="@+id/iv_avatar"            android:layout_width="60dp"            android:layout_height="60dp"            android:layout_centerInParent="true"/>    RelativeLayout>LinearLayout>

代码:

/** * Created by keithwang on 16/8/14. */public class BlurTestActivity extends BaseActivity{    private ImageView blurImageView;    private ImageView avatarImageView;    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_blur_test);        findViews();        initData();    }    private void findViews(){        blurImageView = (ImageView) findViewById(R.id.iv_blur);        avatarImageView = (ImageView) findViewById(R.id.iv_avatar);    }    private void initData(){        Glide.with(this).load(R.drawable.placeholder_avatar)                .bitmapTransform(new BlurTransformation(this, 25), new CenterCrop(this))                .into(blurImageView);        Glide.with(this).load(R.drawable.placeholder_avatar)                .bitmapTransform(new CropCircleTransformation(this))                .into(avatarImageView);    }}

运行起来效果如下所示:

BlurTransformation 这个就是毛玻璃的实现类

更多相关文章

  1. 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
  2. Android(安卓)程序的反破解技术
  3. APK反破解之三:NDK编译.so动态库
  4. android adb 源码框架分析(1 系统)
  5. 一个大型新闻app的骨架(android)
  6. Android(安卓)Service生命周期及用法!
  7. 在 Android(安卓)中调用二进制可执行程序(native executable)
  8. 牛人必修 Ant编译android工程 ,并Proguard代码混淆,v4混淆配置
  9. Mono for Android, C# for Android,Monodroid初尝鲜-[Hello, Mono

随机推荐

  1. android开发--RelativeLayout用到的一些
  2. Android(安卓)获取基站信息
  3. Android预制APP第一次打开时不弹权限提示
  4. Android中WebView如何加载JavaScript脚本
  5. android手机两种方式获取IP地址
  6. Android(安卓)SDK下载和更新失败的解决方
  7. AndroidのUI布局之layout weight
  8. android debug
  9. include merge的使用
  10. android 设置时区