这篇文章主要介绍了Android实现用户圆形头像和模糊背景,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了Android实现用户圆形头像和模糊背景的具体代码,供大家参考,具体内容如下
1、效果展示

2、在build.gradle(Module)中的dependencies里面加入下面依赖
注意:glide依赖的版本
//图片加载框架
implementation 'jp.wasabeef:glide-transformations:2.0.2' //图片模糊效果
compile 'com.github.bumptech.glide:glide:3.7.0'
//圆形头像
implementation 'de.hdodenhof:circleimageview:2.2.0'
3、布局实现,activity_head.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".charttest.HeadActivity">
<ImageView
android:id="@+id/mImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/civ_head"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/head"
android:layout_gravity="center"
/>
</FrameLayout>
4、核心类实现HeadActivity.java
package com.example.crab_breeding.charttest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.example.crab_breeding.R;
import jp.wasabeef.glide.transformations.BlurTransformation;
public class HeadActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_head);
//获取圆形头像和背景的imageview实例
ImageView mImage=findViewById(R.id.mImage);
ImageView civ_head=findViewById(R.id.civ_head);
//背景模糊实现
// 参数20 表示模糊背景图片的放大参数 越大背景图片越模糊
Glide.with(HeadActivity.this)
.load(R.drawable.head)
.bitmapTransform(new BlurTransformation(HeadActivity.this,20,2))
.into(mImage);
//头像圆形实现
Glide.with(HeadActivity.this)
.load(R.drawable.head)
.into(civ_head);
}
}
5、完成
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
织梦狗教程
本文标题为:Android实现用户圆形头像和模糊背景
基础教程推荐
猜你喜欢
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- Android多返回栈技术 2023-04-15
- android studio按钮监听的5种方法实例详解 2023-01-12
- iOS开发教程之XLForm的基本使用方法 2023-05-01
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- Android中的webview监听每次URL变化实例 2023-01-23
- Flutter手势密码的实现示例(附demo) 2023-04-11
