Transparent RelativeLayout which sits "on top" of a surfaceview? - android

I've got a canvas drawn (I have to keep the canvas, it's doing other things). I'm drawing N amount of images in this canvas, I'm wondering how would I make them clickable? also does anyone know how I could test if a bitmap is in a certain co-ord? Alternatively how would I create a button which was an image on a canvas? or even, How would I create a Transparent RelativeLayout on top of a Surfaceview?
edit.. anyone?? I'm thinking Relative Layout on top of Surfaceview would be the best way to go!
edit2: Setting things to transparent seems to just set the background to black and not actually let me see the Surfaceview I have defined under it.
Thanks,

Turns out it's already transparent and setting it to transparent just makes it black! you also just use bringtofront(); in order to make it sit "on top" of anything.

Related

How do I add standard scroll bars to a SurfaceView?

I got a SurfaceView, in which I display a bitmap that is much larger than the actual area of the SurfaceView, so I have implemented a way for the user to slide their finger on the bitmap and move it up and down. When doing so, I would like to be able to display a vertical scroll bar, preferably the standard Android scroll bars, instead of drawing something custom.
The thing is, I would like my SurfaceView to stay the size of the screen, that is I don't want to scroll the SurfaceView itself, I just want to create the illusion that the user is scrolling the contents, and therefore display the scrollbars.
I tried setting android:scrollbars = "vertical" in the layout's XML, I tried mSurfaceView.setVerticalScrollBarEnabled(true); and I tried awakenScrollBars(); whenever the user touches the SurfaceView, however none of those displays the scrollbars.
So, is it possible to display the standard Android scrollbar on a SurfaceView?
short answer is: no!
everything that the SurfaceView ever draws on the screen is whatever you directly call to be drawn using the whole lockCanvas and unlockCanvasAndPost that you know about.
Putting those parameters in the XML make it possible for you to read them in Java via the AttributeSet in the constructor, but that's only for configuration, it won't drawn anything.

It is possible to move a tiled background? (infinite scroll with TileMode.REPEAT)

I am developing a game
First of all my game will be very simple, so i would prefer not to use libraries or opengl or canvas, i would prefer to achieve this with simple imageviews or normal views, or at least by the simplest way possible. For example with android bitmap tile mode:
public static void setBackground(Bitmap bmp, ViewGroup layout){
BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
layout.setBackgroundDrawable(bitmapDrawable);
}
I want to develop a simple 2D/3D hybrid spaceship game. The screen will be the vision from the spaceship cockpit, and you will move the spaceship touching a joystick that i have allready done. So the background will be a universe background, i mean a huge black image with stars, and this image must be moved to all directions with the joystick simulating that the spaceship is changing it's direction, and when you move a lot to the right for example, the background image must start from the begining to simulate that the space ship is still moving to the right without any limitation
As i have mentioned, i have the joystick now, and i know how to move a imageview with the joystick, the problem is that i dont know how to create a infinite imageview with tiles correctly, because when i move the background containing the tile imagedrawable then the image dissapears from the screen.
This is an example of an image for using with the infinite background:
I had a similar problem and found a solution which uses only XML. In a vertical ScrollView that has a height of 50000dp, my tiled background image repeats as much as needed to fill this height. As a result, scrolling would create the desired effect of stars flying by (using your image as an example).
Use a ScrollView, its background does not matter. Height set to wrap_content.
Inside this ScrollView, place another layout (I happen to have a ConstraintLayout). This is the background that matters. Height set to wrap_content. Set the background of this to: android:background="#drawable/repeating_background"
Create a new drawable called repeating_background.xml with the following code:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/stars_image"
android:tileModeY="repeat"
/>
where tileModeY="repeat" makes stars_image (png, jpeg, etc.) repeat only vertically. You would want to use tileMode="repeat" since that can handle X and Y. tileMode="mirror" is something you could explore since it reflects the image to get rid of the appearance of any seams if the background color changes.
That's it! If you had set this same background to the ScrollView itself, then it would simply tile your image, but this tiled background would remain static while the contents of your ScrollView scrolled.

making UI layout with custom shape buttons

I want to make a layout like this. This app will be for my own use only i don't have much experience in graphics with android. I have draw these images and saved as PNG separately. I tried to put them in a layout, but i face to many difficulties with spacing and correct placing. But PNG is a rectangle and it clicks outside the image. So i think about preparing all possible situation and load all image as background. Touchable area rectangle(invisible) would be drawn inside button.
Is it a good practice to load image as a background when touch? I would have 16x4=64 backgrounds
What difficulties i can face in the future?
Should i stick to the black background and load separate buttons?
If above "Yes", then to draw background and image is better to resize image in pixels in a drawing SW like Corel? In my case 1280x720
1:
And the touch area would be something like this so i don't think it is possible to misclick it?
2:
With classic View, you won't be able to do non-rectangular view (you can draw want ever you want but your touch area is still rectangular).
The easiest way is to handle the onTouchEvent on a large View (fillin the screen with your image as background) with a View.OnTouchListener and calculate above which (fake) button you are.
For highlights you can use SurfaceView (could be the tricks #Frank.N.Stein talks about).
The hardest way is to use OpenGL graphics ... good luck for a someone who doesn't "have much experience [...]".

Android: how can you tell that a View has become Visible?

I have a FrameView containing a full-screen ImageView on top and a full-screen SurfaceView underneath. The ImageView starts out INVISIBLE while I display the SurfaceView. Now I set the ImageView to VISIBLE and want to update what is on the SurfaceView, unseen.
But the ImageView is not yet really visible. I have to wait until the ImageView is actually visible before messing with the SurfaceView. How is this done?
The only way I found was to wait 50ms (nothing less would do) before messing with the SurfaceView. Which happens to work reliably on my device, but is obviously a hack.
To be more specific: on the SurfaceView I am preparing a movie. Which makes the screen go black. I am trying to avoid the black by covering it with an image.
Any help appreciated!
You can use View.onVisibilityChanged().

Android: Draw image over button

Is it possible to draw an image over another view (like a button) and still have the view work normally? The user would still be able to click on the button even though there is another image on top of it. I want to draw some mostly transparent pngs over my layout for lighting effects, but I want to make sure everything will still work correctly.
Try using a RelativeLayout with an ImageView on top of the widget(s) in your app. See this question for a quick example.

Categories

Resources