Android圆形头像和模糊背景 Android实现用户圆形头像和模糊背景

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Android圆形头像和模糊背景 Android实现用户圆形头像和模糊背景

灵猫小西   2021-04-21 我要评论
想了解Android实现用户圆形头像和模糊背景的相关内容吗,灵猫小西在本文为您仔细讲解Android圆形头像和模糊背景的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android用户圆形头像,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、完成

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们