Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Dynamic iOS-like blur of underlying Views for Android

License

NotificationsYou must be signed in to change notification settings

Dimezis/BlurView

Repository files navigation

Stand With Ukraine

BlurView

Dynamic iOS-like blur for Android Views. Includes library and small example project.

BlurView can be used as a regular FrameLayout. It blurs its underlying content and draws it as abackground for its children. The children of the BlurView are not blurred. BlurView redraws itsblurred content when changes in view hierarchy are detected (draw() called). It honors its positionand size changes, including view animation and property animation.

How to use

  <eightbitlab.com.blurview.BlurViewandroid:id="@+id/blurView"android:layout_width="match_parent"android:layout_height="wrap_content"app:blurOverlayColor="@color/colorOverlay"><!--Any child View here, TabLayout for example. This View will NOT be blurred-->  </eightbitlab.com.blurview.BlurView>
floatradius =20f;ViewdecorView =getWindow().getDecorView();// ViewGroup you want to start blur from. Choose root as close to BlurView in hierarchy as possible.ViewGrouprootView = (ViewGroup)decorView.findViewById(android.R.id.content);// Optional:// Set drawable to draw in the beginning of each blurred frame.// Can be used in case your layout has a lot of transparent space and your content// gets a too low alpha value after blur is applied.DrawablewindowBackground =decorView.getBackground();blurView.setupWith(rootView)// Optionally pass RenderEffectBlur or RenderScriptBlur as the second parameter           .setFrameClearDrawable(windowBackground)// Optional. Useful when your root has a lot of transparent background, which results in semi-transparent blurred content. This will make the background opaque           .setBlurRadius(radius)

Always try to choose the closest possible root layout to BlurView. This will greatly reduce the amount of work needed for creating View hierarchy snapshot.

SurfaceView, TextureView, VideoView, MapFragment, GLSurfaceView, etc

BlurView currently doesn't support blurring of these targets, because they work only with hardware-accelerated Canvas, and BlurView relies on a software Canvas to make a snapshot of Views to blur.

Gradle

Since JCenter is closing, please usehttps://jitpack.io/ and release tags as the source of stableartifacts.

implementation'com.github.Dimezis:BlurView:version-2.0.6'

Rounded corners

It's possible to set rounded corners without any custom API, the algorithm is the same as with other regular View:

Create a rounded drawable, and set it as a background.

Then set up the clipping, so the BlurView doesn't draw outside the corners

blurView.setOutlineProvider(ViewOutlineProvider.BACKGROUND);blurView.setClipToOutline(true);

Related thread -#37

Why blurring on the main thread?

Because blurring on other threads would introduce 1-2 frames of latency.For what it's worth,RenderEffectBlur performs blur on the Render Thread.

Compared to other blurring libs

  • The main advantage of BlurView over almost any other library is that it doesn't trigger redundant redraw.
  • The BlurView never invalidates itself or other Views in the hierarchy and updates only when needed relying on just a Bitmap mutation, which is recorded on a hardware-accelerated canvas.
  • It supports multiple BlurViews on the screen without triggering a draw loop.
  • It uses optimized RenderScript Allocations on devices that require certain Allocation sizes, which greatly increases blur performance.
  • It allows choosing a custom root view to take a snapshot from, which reduces the amount of drawing traversals and allows greater flexibility.
  • Supports blurring of Dialogs (and Dialog's background)

Other libs:

License

Copyright 2024 Dmytro SaviukLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at   http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

About

Dynamic iOS-like blur of underlying Views for Android

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Languages


    [8]ページ先頭

    ©2009-2025 Movatter.jp