2012-01-25 116 views
6

所以我想要做的是创建一个线性布局的半透明和模糊的背景。使线性布局半透明和模糊

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

感谢您的帮助!

+0

我不知道,没有ü尝试把这个在Manifest中添加标签? android:theme =“@ android:style/Theme.Dialog” –

回答

2

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

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

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

+1

是的,它适用于窗口,但是在布局本身并不适用,为了更清楚地说明它的两个并排线性布局(横向)和右边的需要模糊,但仍然存在,并且背景不牢固,所以它不能被覆盖,因为我仍然想显示那里有什么,但难以辨认 – Samuel

+0

我找不到应用线性布局的方法。但我有一个想法。您可以使用该窗口获得半透明的背景。而且,在你想要背景的地方,你可以应用背景。并且不要为不想要的背景应用背景。例如,在你的情况下,你可以为左边的一个线性布局应用背景,而不要为其他线性布局应用任何背景。我认为这可以工作。不是正确的方式。 – san

+0

然而窗口确实有一个非固体图像的背景 – Samuel

0

如果你想查看的任何背景半透明然后用下面的代码

android:background="@null" 

它的工作我的EditText。而且据我所知,应该对任何view.So工作,一旦尝试了这一个

+0

半透明!=透明 – Graham

0

如何试图GLSurfaceView:

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

在Android SDK中有在得到透光面(应用程序/ 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 Channel Blur

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

blur a image at android

另一个例子是应用程序/ 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); 
    } 
} 
+0

在第二个示例中,已弃用标志“FLAG_BLUR_BEHIND”。 – Ayoub