Android實(shí)現(xiàn)用戶圓形頭像和模糊背景
本文實(shí)例為大家分享了Android實(shí)現(xiàn)用戶圓形頭像和模糊背景的具體代碼,供大家參考,具體內(nèi)容如下
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、布局實(shí)現(xiàn),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、核心類實(shí)現(xiàn)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實(shí)例
ImageView mImage=findViewById(R.id.mImage);
ImageView civ_head=findViewById(R.id.civ_head);
//背景模糊實(shí)現(xiàn)
// 參數(shù)20 表示模糊背景圖片的放大參數(shù) 越大背景圖片越模糊
Glide.with(HeadActivity.this)
.load(R.drawable.head)
.bitmapTransform(new BlurTransformation(HeadActivity.this,20,2))
.into(mImage);
//頭像圓形實(shí)現(xiàn)
Glide.with(HeadActivity.this)
.load(R.drawable.head)
.into(civ_head);
}
}
5、完成
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- android10 隱藏SystemUI鎖屏下的多用戶圖標(biāo)的示例代碼
- Android 如何攔截用戶頻繁操作(點(diǎn)擊事件)
- Android實(shí)現(xiàn)簡單用戶注冊案例
- Android啟動頁用戶相關(guān)政策彈框的實(shí)現(xiàn)代碼
- 詳解Android Studio實(shí)現(xiàn)用戶登陸界面demo(xml實(shí)現(xiàn))
- android實(shí)現(xiàn)記住用戶名和密碼以及自動登錄
- Android權(quán)限如何禁止以及友好提示用戶開通必要權(quán)限詳解
- Android百度地圖定位、顯示用戶當(dāng)前位置
- Android模擬用戶點(diǎn)擊的實(shí)現(xiàn)方法
- Android EditText 監(jiān)聽用戶輸入完成的實(shí)例
- Android 用戶Session管理的設(shè)計(jì)方案
- Android基于AlarmManager實(shí)現(xiàn)用戶在線心跳功能示例
- Android 多用戶詳情
相關(guān)文章
Android Studio 中運(yùn)行 groovy 程序的方法圖文詳解
這篇文章主要介紹了Android Studio 中 運(yùn)行 groovy 程序的方法,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03
Android Studio3.2中導(dǎo)出jar包的過程詳解
這篇文章主要介紹了Android Studio3.2中導(dǎo)出jar包的過程,本文分步驟給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-06-06
Android 百度地圖marker中圖片不顯示的解決方法(推薦)
下面小編就為大家分享一篇Android 百度地圖marker中圖片不顯示的解決方法(推薦),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01
Android自定義view實(shí)現(xiàn)滑動解鎖效果
這篇文章主要為大家詳細(xì)介紹了Android自定義view實(shí)現(xiàn)滑動解鎖效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-05-05
Android基于OpenCV實(shí)現(xiàn)霍夫直線檢測
霍夫變換利用點(diǎn)與線之間的對偶性,將圖像空間中直線上離散的像素點(diǎn)通過參數(shù)方程映射為霍夫空間中的曲線,并將霍夫空間中多條曲線的交點(diǎn)作為直線方程的參數(shù)映射為圖像空間中的直線。給定直線的參數(shù)方程,可以利用霍夫變換來檢測圖像中的直線。本文簡單講解Android的實(shí)現(xiàn)2021-06-06
Android編程實(shí)現(xiàn)屏幕禁止休眠的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)屏幕禁止休眠的方法,分析了Android的Manifest.xml設(shè)置與代碼實(shí)現(xiàn)兩種操作技巧,需要的朋友可以參考下2016-10-10
Android中用onSaveInstanceState保存Fragment狀態(tài)的方法
這篇文章主要介紹了Android中用onSaveInstanceState保存Fragment狀態(tài)的方法,onSaveInstanceState可以將數(shù)據(jù)保存在Fragment或Activity中,需要的朋友可以參考下2016-04-04
Android 使用AsyncTask實(shí)現(xiàn)多線程斷點(diǎn)續(xù)傳
本文將詳細(xì)講解如何使用AsyncTask來實(shí)現(xiàn)多線程的斷點(diǎn)續(xù)傳下載功能,感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧2018-05-05
Android點(diǎn)擊Button實(shí)現(xiàn)功能的幾種方法總結(jié)
當(dāng)Button有多個或者Button的使用次數(shù)很多時,我們需要采用綁定監(jiān)聽器的做法,其實(shí),綁定監(jiān)聽器也有幾種方法,不過,我在這里就不一一列舉了,畢竟那些方法在實(shí)際的應(yīng)用中也不常見2013-10-10

