I have a Unity scene as a part of a view in my Android app. This is how I set it after exporting the project from Unity editor.
protected void onCreate(Bundle savedInstanceState) {
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
mUnityPlayer = new UnityPlayer(this);
binding = DataBindingUtil.setContentView(this, R.layout.main);
mUnityPlayer.setBackgroundResource(R.drawable.some_drawable);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
binding.scene.addView(mUnityPlayer.getView(), 0, lp);
}
This works fine. Now I need to take the screenshot of this scene and show it in another ImageView. The problem is that UnityPlayer is a FrameLayout and I expected to use getDrawingCache() on that to get the screenshot.
But that only returns me my background image R.drawable.some_drawable and any text and other info in the Unity scene isn't present in the screenshot. I think this is happening probably because the other contents aren't part of a FrameLayout and are rendered on some TextureView or something. I may be completely wrong. But I can't figure out how to get a screenshot of the contents inside the scene as a Bitmap that I can set on another imageView.
Any pointers or help would be appreciated. Thanks!
Related
I know that there are some design layouts (for example TEXT, TITLE, COLUMS etc.)
What I would like to show is just a picture from drawable. When I use the TEXT Layout with .addImage, the picture is in background (darker). I tried to use the TITLE Layout, but in this case I also see a black vignette at the bottom.
I would like to screen only a picture. And I'm using the devicedefault theme, because I've also some cards with only text or columns etc.
I tried to use an EMBEDDED Layout with a custom XML file, but the picture is not fullscreen. Is there a simple solution for this problem? Thank you in advance.
Here is also the code, im still having trouble:
private void addImageView(LinearLayout layout) {
ImageView iv = new ImageView(this);
Object drawable;
iv.Drawable(Drawable drawable); //problem here?
iv.setPadding(0, 0, 0, 0);
iv.setAdjustViewBounds(true);
iv.setScaleType(ImageView.ScaleType.CENTER);
}
private void createCards() {
mCards = new ArrayList<CardBuilder>();
mCards.add(new CardBuilder(this, CardBuilder.Layout.TITLE)
.setText("This is TITLE")
.addImage(R.drawable.title)
.setImageLayout( ImageLayout.FULL)); //also problem here?
Please look at this link and I am sure it will help you a lot, I was also using it on Google Glass Card Design.
You can simply set an ImageView as the content of the Activity:
ImageView image = new ImageView(this);
image.setScaleType(ImageView.ScaleType.CENTER_CROP);
image.setImageDrawable(yourDrawable);
// or image.setImageResource(R.drawable.your_image);
// or image.setImageBitmap(yourBitmap);
setContentView(image, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
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);
}
}
atm i'm using this code, but this code doesn't works for me, because the code is stretching the Image on the screen, i dont want that, i need that the image uses his real size (200x210)
FrameLayout fl = new FrameLayout(this.getApplicationContext());
splash = new ImageView(getApplicationContext());
splash.setImageResource(R.drawable.logo2);
fl.addView(splash);
fl.setForegroundGravity(Gravity.CENTER);
fl.setBackgroundColor(Color.BLACK);
setContentView(fl);
How to do it without making a giant image that it is using all the screen?
You have to specify scalType if you don't want imageview to stretch your image.
splash.setScaleType(ScaleType.CENTER);
use this properties of ImageView as shown here:
splash.setAdjustViewBounds(true);
and tell me if it is working.
I've got a programmatically-created layout, where when my app gets ads, it'll show an admob view, pushing my existing GLView down and resizing it.
However, although it initially seems to be pushing my GLView down, the GLView suddenly resets itself and overlaps the AdMob view and resets itself to its original size.
This is what I do to resize and reposition the GLSurfaceView:
Main.Instance.admobView.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(Main.Instance.GLView.getWidth(),
Main.Instance.GLView.getHeight() - AdSize.BANNER.getHeight());
params.topMargin = AdSize.BANNER.getHeight();
Main.Instance.GLView.setLayoutParams(params);
Main.Instance.TopView.requestLayout();
This is what I get in the end:
http://i.stack.imgur.com/UuwKA.png
Does anyone have any idea what could be causing this?
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);