【问题标题】:Blur and Unblur images in collapsing Toolbar折叠工具栏中的模糊和取消模糊图像
【发布时间】:2018-07-04 22:02:39
【问题描述】:

在我的CountryImageInfo.java 中,我有一个折叠工具栏,里面有一张图片。 这是它的样子:

我想知道如何在图像塌陷时对其进行模糊处理,以及如何在图像再次倒塌时对其进行去模糊处理。类似于iOS的通知栏,不知道大家有没有熟悉... 我见过类似的问题,但不同的是,有些人问如何模糊它被折叠了(不是我要问的。我是在它折叠时问的。逐渐模糊)......

这是我的 XML,顺便说一下,所有内容都包含在 CoordinatorLayout 中:

<android.support.design.widget.AppBarLayout
    android:id="@+id/testeparainfo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/actionBarDivider">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/backgroundcollapsedtoolbarinfo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="exitUntilCollapsed|scroll">


        <ImageView
            android:id="@+id/imgCountryInfoFoto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop" />

        <ImageView
            android:id="@+id/imgCountryInfoEscuro"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:background="@drawable/background_pais_info"
            android:scaleType="centerInside" />


        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbaridinfo"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        </android.support.v7.widget.Toolbar>

        <TextView
            android:id="@+id/txtNomePaisInfo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_marginStart="30dp"
            android:layout_marginTop="520dp"
            android:paddingBottom="10dp"
            android:text="TextView"
            android:textColor="@android:color/background_light"
            android:textSize="35sp"
            app:layout_anchor="@+id/testeparainfo"
            app:layout_anchorGravity="left|bottom" />


    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

更新:

复制图像并不是我真正想要的,因为这些图像有点大,所以除了复制图像之外还有其他方法吗? 我搜索了一些库,但找不到任何可以满足我需求的东西...我可以将所有图像都变蓝,有没有办法设置侦听器以在用户向上拖动折叠条时开始模糊?请帮忙,我已经尝试了很多东西!

【问题讨论】:

  • 查看answer。它可能会帮助你
  • @BrijeshJoshi 其实不是因为问这个问题的人想要的只是图像折叠时的模糊,而不是逐渐的啊
  • 是的,但是如果您查看接受的答案,您会发现该人已在应用栏上添加了 OnOffsetChangedListener,该应用栏提供了根据他设置的偏移量已更改的详细信息blurView 的 alpha。所以最终这会对你有所帮助。
  • 如果您仍有问题,请告诉我们
  • 我试图按照答案所说的去做,但是当我尝试运行我的应用程序时它给了我这个错误:More than one file was found with OS independent path 'lib/arm64-v8a/libRSSupport.so'

标签: java android xml android-collapsingtoolbarlayout android-blur-effect


【解决方案1】:

试试这个Android Blurry Library

@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    double percentage = (double) Math.abs(verticalOffset) / collapsingToolbar.getHeight();
    if (percentage > 0.8) {
        collapsingToolbar.setTitle("Collapsed");
    } else {
        collapsingToolbar.setTitle("Expanded");
    }

Blurry.with(context)
  .radius(10 * percentage)
  .sampling(8)
  .color(Color.argb(66, 255, 255, 0))
  .async()
  .animate(500)
  .onto(blurryImage); // imgCountryInfoEscuro
}

【讨论】:

  • “rootView”是什么?
  • 这个解决方案对我没有帮助
  • @AndréSilva rootView 是blurryImage // imgCountryInfoEscuro 检查我的答案更新,您也可以使用async 或不使用。 `
【解决方案2】:

我用过RealtimeBlurView。要使用它,请在您的应用模块的build.gradle 中进行更改。

在你的 build.gradle 中添加依赖:

dependencies {
    compile 'com.github.mmin18:realtimeblurview:1.1.2'
}
android {
    buildToolsVersion '24.0.2'                 // Use 23.0.3 or higher
    defaultConfig {
        minSdkVersion 15
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true    // Enable RS support
    }
}

必要时添加proguard规则:

-keep class android.support.v8.renderscript.** { *; }

然后在您的CollapsingToolbarLayout 中添加以下视图

<com.github.mmin18.widget.RealtimeBlurView
            android:id="@+id/blurView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:realtimeBlurRadius="20dp"
            app:realtimeOverlayColor="#8000" />

并在您的活动中添加以下代码。

final AppBarLayout appBar = findViewById(R.id.testeparainfo);
final RealtimeBlurView blurView = findViewById(R.id.blurView);
blurView.setAlpha(1F);
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
    @Override
    public void onOffsetChanged(final AppBarLayout appBarLayout, final int verticalOffset) {
        float offsetAlpha = (appBarLayout.getY() / appBar.getTotalScrollRange());
        blurView.setAlpha(offsetAlpha * -1);
    }
});

求助answer

【讨论】:

  • 我试试看!但只有一件事,我如何添加proguard rules?我在哪里安装它?
  • 如果你到现在还没有proguard那就没必要了
  • 它仍然给我这个错误:More than one file was found with OS independent path 'lib/arm64-v8a/libRSSupport.so'
  • 你能分享你的 build.gradle 文件吗?这样我就可以调查它,并提供适当的信息
  • 您得到的错误可能是因为 RealTimeBlurView 与其他一些库冲突。跟踪
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-11
  • 2015-04-16
  • 1970-01-01
  • 1970-01-01
  • 2015-06-10
  • 1970-01-01
相关资源
最近更新 更多