【问题标题】:Android: Blur listview behind a layoutAndroid:在布局后面模糊列表视图
【发布时间】:2016-04-03 18:56:56
【问题描述】:

我有一个列表视图和一个位于列表视图前面的布局。我希望该布局以他背后的列表视图的模糊为背景。就像图片中一样。模糊根据列表视图滚动而变化。我该怎么做呢?

【问题讨论】:

    标签: android layout blur uiblureffect


    【解决方案1】:

    这个库就是你需要的https://github.com/Dimezis/BlurView

    <eightbitlab.com.blurview.BlurView
        android:id="@+id/blurView"
        android:layout_width="match_parent"
        android:layout_height="66dp"
        android:layout_alignParentBottom="true"
        >
        <!--anything below this view will be blured-->
    </eightbitlab.com.blurview.BlurView>
    

    在 app.gradle 默认配置中

        renderscriptTargetApi 23
        renderscriptSupportModeEnabled true
    

    在活动中

        blurView = (BlurView) findViewById(R.id.blurView);
    
        final View decorView = getWindow().getDecorView();
        final View rootView = decorView.findViewById(android.R.id.content);
        final Drawable windowBackground = decorView.getBackground();
    
        blurView.setupWith(rootView)
                .windowBackground(windowBackground)
                .blurAlgorithm(new RenderScriptBlur(this, true)) //Preferable algorithm, needs RenderScript support mode enabled
                .blurRadius(10);
    

    【讨论】:

      【解决方案2】:

      参考本博客post

      private void blur(Bitmap bkg, View view, float radius) {
              Bitmap overlay = Bitmap.createBitmap(
                      view.getMeasuredWidth(),
                      view.getMeasuredHeight(),
                      Bitmap.Config.ARGB_8888);
      
              Canvas canvas = new Canvas(overlay);
      
              canvas.drawBitmap(bkg, -view.getLeft(),
                      -view.getTop(), null);
      
              RenderScript rs = RenderScript.create(this);
      
              Allocation overlayAlloc = Allocation.createFromBitmap(
                      rs, overlay);
      
              ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(
                      rs, overlayAlloc.getElement());
      
              blur.setInput(overlayAlloc);
      
              blur.setRadius(radius);
      
              blur.forEach(overlayAlloc);
      
              overlayAlloc.copyTo(overlay);
      
              view.setBackground(new BitmapDrawable(
                      getResources(), overlay));
      
              rs.destroy();
          }
      

      【讨论】:

      • 这不是要求艾敏
      猜你喜欢
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      • 2016-08-08
      • 1970-01-01
      相关资源
      最近更新 更多