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

相关推荐
福柯柯9 分钟前
Android ContentProvider的使用
android·contenprovider
不想迷路的小男孩9 分钟前
Android Studio 中Palette跟Component Tree面板消失怎么恢复正常
android·ide·android studio
餐桌上的王子10 分钟前
Android 构建可管理生命周期的应用(一)
android
菠萝加点糖14 分钟前
Android Camera2 + OpenGL离屏渲染示例
android·opengl·camera
用户20187928316725 分钟前
🌟 童话:四大Context徽章诞生记
android
yzpyzp33 分钟前
Android studio在点击运行按钮时执行过程中输出的compileDebugKotlin 这个任务是由gradle执行的吗
android·gradle·android studio
aningxiaoxixi43 分钟前
安卓之service
android
TeleostNaCl2 小时前
Android 应用开发 | 一种限制拷贝速率解决因 IO 过高导致系统卡顿的方法
android·经验分享
用户2018792831672 小时前
📜 童话:FileProvider之魔法快递公司的秘密
android
vocal5 小时前
【我的安卓第一课】Android 多线程与异步通信机制(1)
android