使线性布局半透明和模糊

发布于 2024-12-29 02:33:25 字数 136 浏览 3 评论 0原文

所以我想做的是为线性布局创建半透明且模糊的背景。

现在我有一个完全黑色的线性布局,覆盖了一些必须购买密钥才能显示的信息,但是我希望它被模糊,而不是完全覆盖,因为它破坏了布局,它需要留在那里,只是模糊且难以辨认。

感谢您的帮助!

So what I'm trying to do is create a translucent and blurry background to a linear layout.

Right now I have a linear layout thats completely black covering up some information that a key must be purchased to show, however I would like it to be blurred out, not completely covered as it ruins the layout, it needs to stay there, just blurry and illegible.

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终弃我 2025-01-05 02:33:25

我不确定 Linearlayout 。但对于您的活动,您可以尝试这个。

getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

并使用 setContentView(R.layout.your_layout); 方法

I'm not sure for Linearlayout. But for your activity you can try this.

getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

and use the setContentView(R.layout.your_layout); method

冷夜 2025-01-05 02:33:25

如果您想让任何视图背景半透明,请使用下面的代码,

 android:background="@null" 

它适用于 EditText。而且据我所知,它应该适用于任何视图。所以一旦尝试一下这个

If you want to make any View Background translucent then use below code

 android:background="@null" 

it work me for EditText. And AFAIK it should work for any view.So once try for this one

玩套路吗 2025-01-05 02:33:25

尝试 GLSurfaceView 怎么样:

http://developer.android.com/resources/articles/glsurfaceview .html

在 Android SDK 中,有一个获取半透明表面的示例 (app/TranslucentActivity.java),主要是设置 Alpha 通道:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create our Preview view and set it as the content of our
    // Activity
    mGLSurfaceView = new GLSurfaceView(this);
    // We want an 8888 pixel format because that's required for
    // a translucent window.
    // And we want a depth buffer.
    mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    // Tell the cube renderer that we want to render a translucent version
    // of the cube:
    mGLSurfaceView.setRenderer(new CubeRenderer(true));
    // Use a surface format with an Alpha channel:
    mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    setContentView(mGLSurfaceView);
}

有关使用 Alpha 通道的其他线程,请参阅:

Alpha 通道模糊

​​如何模糊和调暗图像以用作活动背景?

在 android 上模糊图像

另一个例子是 app/TranslucentBlurActivity.java (来自 Android SDK):

public class TranslucentBlurActivity extends Activity {
    /**
     * Initialization of the Activity after it is first created.  Must at least
     * call {@link android.app.Activity#setContentView setContentView()} to
     * describe what is to be displayed in the screen.
     */
    @Override
    protected void onCreate(Bundle icicle) {
        // Be sure to call the super class.
        super.onCreate(icicle);

        // Have the system blur any windows behind this one.
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
                WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

        // See assets/res/any/layout/translucent_background.xml for this
        // view layout definition, which is being set here as
        // the content of our screen.
        setContentView(R.layout.translucent_background);
    }
}

How about trying GLSurfaceView:

http://developer.android.com/resources/articles/glsurfaceview.html

Within Android SDK there is an example on getting translucent surface (app/TranslucentActivity.java), essentially setting the alpha channel:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create our Preview view and set it as the content of our
    // Activity
    mGLSurfaceView = new GLSurfaceView(this);
    // We want an 8888 pixel format because that's required for
    // a translucent window.
    // And we want a depth buffer.
    mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    // Tell the cube renderer that we want to render a translucent version
    // of the cube:
    mGLSurfaceView.setRenderer(new CubeRenderer(true));
    // Use a surface format with an Alpha channel:
    mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    setContentView(mGLSurfaceView);
}

For other threads on using Alpha channel refer to:

Alpha Channel Blur

How can I blur and dim an image to be used as an activity background?

blur a image at android

Another example is the app/TranslucentBlurActivity.java (from Android SDK):

public class TranslucentBlurActivity extends Activity {
    /**
     * Initialization of the Activity after it is first created.  Must at least
     * call {@link android.app.Activity#setContentView setContentView()} to
     * describe what is to be displayed in the screen.
     */
    @Override
    protected void onCreate(Bundle icicle) {
        // Be sure to call the super class.
        super.onCreate(icicle);

        // Have the system blur any windows behind this one.
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
                WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

        // See assets/res/any/layout/translucent_background.xml for this
        // view layout definition, which is being set here as
        // the content of our screen.
        setContentView(R.layout.translucent_background);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文