I have a GLSurfaceView with a drawable as background, however only the background is visible when rendered without surfaceView.setZOrderOnTop(true)
I need to avoid using setZOrderOnTop(true) because there are static TextView's being used on top of the GLSurfaceView.
Any suggestions for getting this to work?
GLSurfaceView cannot really have a background. The way a surface view works is by cutting a hole through your Activity's window and showing another surface behind. Setting setZOrderOnTop(true) moves the surface above the Activity's window.
false! You can do it.
Just an example to show how it works.
glRenderer = new OpenGLRenderer(context);
view = new GLSurfaceView(context);
view.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
view.setRenderer(glRenderer);
view.getHolder().setFormat(PixelFormat.RGBA_8888);
view.getHolder().setFormat(PixelFormat.TRANSLUCENT);
view.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
Then use framelayout to put a view under glsurfaceview!
Try setZOrderMediaOverlay(true); which should put the gl layer above the background but below the window.
Well, since GLSurfaceView is just another view, why not use a FrameLayout to place the GLSurfaceView on top of the ImageView (or whatever you're using to display the drawable.)
Related
I have a transparent layout in android, and behind the layout there is an image. how to make the linear blur ? I found examples to make the image itself blur but I don't want to make whole image blue, just only the part that is behind the linear layout.
Set a semitransparent Blur image to the linear layout or simplest set a color to linear layout and set it to semitransparent by defining alpha
edited solution
do this...
1.) create a blur copy of the image u have on background.
2.) clip the image by using
Bitmap croppedBmp = Bitmap.createBitmap(originalBmp, startX, startY, widthLayout , heightOfLayout);
3.) set this image in the Linear Layout using an image-view with height and width attribute as fill-parent.
I have pretty complex solution, so there won't be any code. So, here is idea, step by step:
Let's assume that your layout have just single custom LinearLayout. No ImageView as a background.
What we going to do, is draw background drawable of LinearLayout by our own, so it will first draw full image and then draw blurred square from the same image on top. Content of LinearLayout might be moved to desired position using paddings.
So, create something like MyLinearLayout and put it to your layout resource. Provide required constructors.
Override onAttachedToWindow() and onDetachedFromWindow() methods. Inside them we should load our background Bitmap and recycle it accordingly. Let's name it mBackground
Override draw() method. Inside it we're going to first draw our mBackground.
Then, you can use Canvas#clipRect() method to crop drawing area of Canvas to some specified rectangle. In your case, this rectangle should be the area below your content. You can figure it out using View#getPadding*() methods. Don't forget to call canvas#save() before clipping drawing area.
Now you can draw your bitmap once again with blur (I don't know which method exactly you're using, so let's assume that you know how to do it... but you still can share it with us :) ). Cool thing is that you can just draw the same Bitmap once again in full scale - since we had called clipRect before, it will be drawn only within this area. Don't forget to call canvas#restore() after drawing background.
Call super.draw() to draw rest of the stuff, that your LinearLayout contains.
I'm trying to make a circle of one color on a background of another.
background = new ShapeDrawable(new OvalShape());
background.getPaint().setColor(main.getResources().getColor(R.color.XXX));
view.SetBackground(background);
will work for the colored circle, and
view.setBackgroundColor(getResources().getColor(R.color.XXX));
will work for the background, but they're mutually exclusive. It just ends up with what I did last. Is there a way to make the circle on another overlapping view or something like that?
setBackgroundColor() is basically a short cut for changing the view's background to a colour drawable.
To do what you want you could try one of the 2 things described below:
Put a view in a FrameLayout, set the background colour in the FrameLayout, and put the shape in the view.
You could also try to use ImageView, which can have a background and another drawable with setImageDrawable() method.
I've created my own View (in which I draw on Canvas), and I want to make another Layer (with buttons etc.) on top of it. How can I do this?
Create a FrameLayout and add the views you want there - the FrameLayout allows for Overlaying of controls.
Just be sure that the top one has some opacity set, otherwise you won't see the controls below it - also be careful of the order you add the Views.
FrameLayout layers = new FrameLayout(this);
CustomViewBottom bottom = new CustomViewBottom(this);
CustomViewOverlay overlay = new CustomViewOverlay(this);
//the overlay class must set the ALPHA property
//of the PAINT object that it uses to draw
layers.addView(bottom);
layers.addView(overlay);
this.setContentView(layers);
How to draw an overlay on a SurfaceView used by Camera on Android?
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!
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
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
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);
}
}
Now I want to insert a ImageView behind the GLSurfaceView.But the GLSurfaceView always draws background color so I can't see the ImageView.I tried glClearColor(0,0,0,0) but it doesn't work.What should I do?Please help me!
Thank you very much.
If I remember correctly you should be able to adapt this
Overlapping Views in Android
to your needs
(relative layout and android:background="#0000")
since GLSurfaceView is a View it should work.
I fixed it.
using
gLSurfaceView.setEGLConfigChooser(8,8,8,8,16,0);
gLSurfaceView.setRenderer(this);
RelativeLayout rl = new RelativeLayout(this);
BgLayout bgl = new BgLayout(this);
gLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
gLSurfaceView.setZOrderOnTop(true);
rl.addView(bgl);
rl.addView(gLSurfaceView);