Android 库模糊对我不起作用,模糊效果不适用

Android library Blurry not working for me,blurring effects do not apply

我正在为我的项目使用模糊库,但它似乎不起作用

我想在相对布局中有一个模糊的背景,所以任何人都可以帮我一些想法吗

这是我片段中的代码

 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    imageView=(ImageView)view.findViewById(R.id.imageView2);
    imageButton=(ImageButton)view.findViewById(R.id.imageButton);
    imageButton2=(ImageButton)view.findViewById(R.id.imageButton2);
    imageButton3=(ImageButton)view.findViewById(R.id.imageButton3);
    textView=(TextView)view.findViewById(R.id.textView);
    seekBar=(SeekBar)view.findViewById(R.id.seekBar);
    rl=(RelativeLayout)view.findViewById(R.id.psrl);
    rl1=(RelativeLayout)view.findViewById(R.id.rl1);

    imageButton.setOnClickListener(this);
    imageButton2.setOnClickListener(this);
    imageButton3.setOnClickListener(this);
    seekBar.setOnSeekBarChangeListener(this);
    createMediaPlayer();
    setAlbumImage();
    runnable=new Runnable() {
        @Override
        public void run() {
            seekBar.setProgress(MainActivity.mediaPlayer.getCurrentPosition());
            handler.postDelayed(runnable,1000);
        }
    };
    handler.postDelayed(runnable,1000);
    rl.setBackground(d);
    Blurry.with(getContext()).radius(25).sampling(2).async().animate(500).onto((ViewGroup)view.findViewById(R.id.psrl));
}

这里是 xml 代码

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:id="@+id/psrl"
>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:background="#7e838c"
    android:alpha="1.0"
    android:id="@+id/rl1">
<TextView
    android:layout_width="210dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="15dp"
    android:layout_marginTop="8dp"
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:gravity="center"
    android:marqueeRepeatLimit="marquee_forever"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:text="Medium Text"
    android:textSize="15dp"
    android:id="@+id/textView"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />
</RelativeLayout>
<ImageView
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:id="@+id/imageView2"
    android:layout_marginTop="109dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:scaleType="fitXY"
    android:background="@drawable/ic_launcher"
    android:adjustViewBounds="true"
    android:padding="8dp"
    android:alpha="1"
    android:cropToPadding="true"/>

<SeekBar
    android:layout_width="370dp"
    android:layout_height="30dp"
    android:id="@+id/seekBar"
    android:layout_above="@+id/imageButton"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="38dp" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton"
    android:background="@drawable/custom2"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="60dp"
    android:layout_centerHorizontal="true"/>
<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton2"
    android:background="@drawable/previous"
    android:layout_alignTop="@+id/imageButton"
    android:layout_alignLeft="@+id/imageView2"
    android:layout_alignStart="@+id/imageView2" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton3"
    android:background="@drawable/skip"
    android:layout_alignTop="@+id/imageButton"
    android:layout_alignRight="@+id/imageView2"
    android:layout_alignEnd="@+id/imageView2" />

</RelativeLayout>

只设置了背景,但没有模糊效果apply.Can有人帮忙吗?

这里是 build.gradle

 android {
compileSdkVersion 24
defaultConfig {
    applicationId "com.example.abhinav.mymusicplayer"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
buildToolsVersion '24.0.2'
productFlavors {
}
}
repositories {
maven {
    url "https://jitpack.io"

}
}
dependencies {
compile 'com.android.support:support-v4:24.2.0'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'jp.wasabeef:blurry:2.1.0'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.github.moondroid.coverflow:library:1.0'
compile 'com.github.davidschreiber:FancyCoverFlow:a54a1e7'
compile files('libs/picasso-2.5.2.jar')
compile files('libs/carousel-api-v1.jar')
}

好的,这是我想要模糊图像时遵循的步骤。

像这样修改您的build.gradle:

android {

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 25

        renderscriptTargetApi 25 <-- must match your targetSdkVersion
        renderscriptSupportModeEnabled true

    }
}

按原样重复库程序。如果这不能解决问题,请尝试这个库:

https://github.com/jrvansuita/GaussianBlur 这对我来说就像一个魅力!!

希望对您有所帮助!!

此库使用 getMeasuredWidth and getMeasuredHeight

当你调用它的时候。在 onViewCreated 中,getMeasuredWidth/getMeasuredHeight 的值将为 0,因此您应该将其移动到 View.post() 中,您可以获得 getMeasuredHeight()/getMeasuredWidth() 实际值,这样您就可以使用 Blury 库

例如:

public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    root.post(new Runnable() {
        @Override
        public void run() {
            // for instance
            Blurry.with(getContext()).radius(25).sampling(2).async().animate(500).onto((ViewGroup)view.findViewById(R.id.psrl));
        }
    });
}