android高斯模糊填充imageview背景

说明:最近碰到一个需求,安卓app显示在线的url图片,然后imageview没占满的部分,使用该图片的模糊背景填充

效果图:

step1:~\app\build.gradle

bash 复制代码
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'jp.wasabeef:glide-transformations:2.0.1'

step2:~\app\src\main\AndroidManifest.xml

bash 复制代码
    <uses-permission android:name="android.permission.INTERNET" />

step3:~\app\src\main\res\layout\activity_main.xml

xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_green_dark">


    <ImageView
        android:id="@+id/iv_bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@mipmap/ic_launcher" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/iv_test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@mipmap/ic_launcher"
            android:visibility="visible" />
    </RelativeLayout>

</FrameLayout>

step4:~\app\src\main\java\com\example\iosdialogdemo\MainActivity.java

java 复制代码
package com.example.iosdialogdemo;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;

import jp.wasabeef.glide.transformations.BlurTransformation;

public class MainActivity extends AppCompatActivity {
    private String url = "http://img.netbian.com/file/2024/0517/small150904ck1C21715929744.jpg";
    private String url2 = "http://img.netbian.com/file/2024/0517/small151245krBn01715929965.jpg";
    private String url3 =  "http://img.netbian.com/file/2024/0519/small190753XKtgH1716116873.jpg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Glide.with(this)
                .load(url)
                .bitmapTransform(new BlurTransformation(this))
                .into((ImageView) findViewById(R.id.iv_bg));

        Glide.with(this)
                .load(url)
                .into((ImageView) findViewById(R.id.iv_test));
    }
}

end

相关推荐
whatever who cares22 分钟前
android中ViewModel 和 onSaveInstanceState 的最佳使用方法
android
毕设源码-钟学长27 分钟前
【开题答辩全过程】以 Android的传统中医诊断管理系统为例,包含答辩的问题和答案
android
脚踏实地,坚持不懈!29 分钟前
Android,Jetpack Compose,坦克大战游戏案例Demo
android·游戏
yzpyzp1 小时前
kotlin的函数前面增加suspend关键字的作用
android·开发语言·kotlin
jiet_h1 小时前
Android Kotlin ObjectAnimator 和 ValueAnimator 全面解析
android·开发语言·kotlin
Android技术之家1 小时前
Kotlin与Compose:Android开发的现代化变革
android·java·开发语言·kotlin
诸神黄昏EX3 小时前
Android SystemServer 系列专题【篇五:UserController用户状态控制】
android
2501_916007473 小时前
Transporter App 使用全流程详解:iOS 应用 ipa 上传工具、 uni-app 应用发布指南
android·ios·小程序·https·uni-app·iphone·webview
叽哥4 小时前
Kotlin学习第 5 课:Kotlin 面向对象编程:类、对象与继承
android·java·kotlin
叽哥4 小时前
Kotlin学习第 6 课:Kotlin 集合框架:操作数据的核心工具
android·java·kotlin