【问题标题】:Android library Blurry not working for me,blurring effects do not applyAndroid 库 Blurry 不适合我,模糊效果不适用
【发布时间】:2017-05-10 11:02:36
【问题描述】:

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

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

这是我的片段中的代码

 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>

只设置了背景,但不应用模糊效果。有人可以帮忙吗?

这里是 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(Module:app)。你启用 renderScript 了吗?
  • @KostasDrak 发布 build.gradle
  • 但您尚未启用渲染脚本以使 Blurry 工作
  • 怎么做?

标签: android android-fragments android-library blurry


【解决方案1】:

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

像这样修改你的 build.gradle:

android {

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 25

        renderscriptTargetApi 25 <-- must match your targetSdkVersion
        renderscriptSupportModeEnabled true

    }
}

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

https://github.com/jrvansuita/GaussianBlur 对我很有用!!

希望对你有帮助!!

【讨论】:

  • 我想模糊相对布局的背景,但它却模糊了整个屏幕。如何只模糊背景?
  • 高斯模糊在 build.gradle 中给出错误“无法解析 com.android.support:app compat-v7:25.0.0”
  • 不管你的targetsdk版本是什么,它还必须是构建工具和renderScript。尝试通过 sdk manager 更新它们
【解决方案2】:

这个库使用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));
        }
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-07
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多