Overlay two bitmaps and rub out the top one - android

I'm having trouble trying to create a screen where I have two bitmaps (one on top of the other so it's totally obscuring the lower one) and "rub out" the top one so it reveals the bottom one under the path of the finger. I realise I may need 3 separate layers (bottom image, top image and then a custom view that handles the finger tracking) but I can't find a method of manipulating the middle layer from the custom view. Can anyone offer some advice on how I might do this?

You should do the whole thing in one View, see this SO question and its answer for more info and links.

Related

think my Android app needs a pinch zoom and pan LAYOUT

So. Iv'e got a straight forward relative layout which I add multiple ImageViews to.
I don't want the images to obscure each other so as they are added they are translated so they don't.
As more ImageViews are added they need to be translated further and further away from the centre of the layout so as not to overlap other images and so they fall off the edge of the user's screen - no problem so far ...
I need to give the user the ability to pan to see the images that are off screen and also zoom in and out (with gestures not buttons) to see all images or focus in on one.
I think the solution to this problem is to modify the layout to allow pinch and pan but all I can find is how to create views that support pinch and pan.
I need each image to be in a separate ImageView.
Forgive me if this is the wrong way to come at this problem but any help would be much appreciated.
This might help explain:
want to scroll about and zoom around this layout (click to see)

What options are there for arranging custom ImageViews

I have recently completed a simple drag and drop shapes game. It had the user drag a shape (ImageView) to another "empty place holder" ImageView.
I now want to make this a little more advanced, instead of dragging a simple shape, I want to make a puzzle of various non-orthogonal shapes, for example breaking a circle into 5 different pieces. What I'm having a problem with right now is how to design the layout. I do not know how to make a truly "custom" shaped ImageView, as far as I can find from my research it's not possible. So my idea for now is to overlap a number of square ImageViews, each of which will have only a subset of an image and the rest transparent. Thus the final output will look like it's a number of custom shaped ImageViews.
Example:
+ + +
Because only the internal sections are "visible" and the rest of the circle is transparent, when all of these pieces are placed in the same spot on the screen, the final image will look like:
I haven't tried this yet... but I foresee at least one problem. When I go to drag the pieces over to this puzzle, they will all "snap" into place when dragged to the same place. Because in reality all I really have here is a picture of a circle inside a ImageView which has some invisible rectangular boundary around it.
Hopefully this situation is clear. Now my questions:
Is it possible to have truly custom shaped ImageViews instead of my idea of overlapping images?
If what I'm thinking is the best way to handle this puzzle idea, then what property can be changed such that the "drop" action does not happen at the same place for all of these puzzle pieces? If I wanted to "drop" the pizza shaped piece, I'd like it to only snap into place when it go close to the top left of the circle.
Note: I am new to Android programming, and somewhat new to Java/XML as well, it’s very likely I’m overlooking something, so please feel free to suggest other approaches as you see fit.
Not really. Overlapping views is generally the way it's done. You could also use one View and override the drawing action yourself (multiple bitmaps drawn at relative locations within the View), but that would make the drag-drop aspect significantly harder.
If the Views are all the same size, with the visible portions in the correct relative placement in each, they should snap together correctly. This is because the snap is (I believe) based on the position of the upper-left corner of the View. If the pizza-shaped piece's visible portion is correct with regards to that, it should snap in at exactly the right spot.
So you have certain places you want to accept the drops, and I'm assuming you know their coordinates, say (d_x,d_y).
Then why not simply monitor the coordinate of the center (p_x,p_y) of image view of the piece you are dragging, say the "pizza" piece, and when the distance between the the piece and drop point is within an acceptable amount accept the drop.
But if you are asking if there is some way to make non-rectangular image views I don't believe that is possible.
However I don't think it is necessary in your case, because I believe even if you want them to drag the piece precisely into place you can calculate the coordinates where the draggable rectangle needs to go with knowledge of the shape of the piece and the assumption that the rectangle wraps the piece.

Curved buttons and a circle

Hey I was wondering if there is any way to do this without going insane with lil buttons built up to make it but basically what I want to do is make two curved buttons around a circle one, is there any way of doing this?
Hers an example of what I kinda want, sorry for how crude the drawing is.
There are two parts in answering this question : how to have buttons looking like this, and getting the touch on the areas you draw.
For the first part, you can use a FrameLayout or a Relative Layout to draw your buttons exactly where you want, and custom images as background (maybe for the circle you can make a ShapeDrawable).
For the second part, it can be very simple : if the Circle (biggest button) is on top of the other two, then this can be ok. But I guess the touchable area on each button will be a rectangle.
Another way to do this is create a custom view, handle the Touch events yourself and based on the X and Y, detect which part has been touched

Animating card dealing

I have looked at the Animation class and am having difficulty understanding how exactly you do things.
In my case, you have a deck of cards in the middle of the screen and I want to animate the deal by showing cards sliding across the screen to the users (who are located on the four edges of the screen).
In some cases, I need to animate the card face-up and then show it face-down in the player hand.
I really am totally lost.
You may take a look at the SurfaceView class, which has a Canvas to draw things. Creating games and animations in general is much easier with Canvas. Good luck!

How to animate views?

I'm working on a game that in some ways is similar to Tetris (imagine a 2D array of colored squares that sometimes move around)
I am trying to animate the individual squares so they will smoothly slide down from coordinate to the next. Since I wanted to use Android's built-in tweening feature, the animation has to apply to the whole View (rather than parts of it). This doesn't work well for me because I only want some of the colored squares to slide down, and the rest of them to stay still.
The (theoretical) solution I came up with to resolve this is to make 2 Views, layered directly on top of each other. The top view is for animating squares when they need to move, and the bottom layer is for the static squares. The animation-layer is transparent until I am ready to animate something. I then simply turn on the colored square in the animation-layer, tween it to the new location, and turn it back off when done. In the same time span, the static-layer just turns squares on and off at the right time to make the whole thing look seamless to the end user.
The proposed solution is just a theory, since I haven't been able to make it work correctly yet. Since I have been having trouble, I was wondering if this is even the best way to solve the problem? Perhaps there is a more elegant solution that I am over looking? Anyone know of a better way?
If you just want to animate a single element check out the namespace android.view.animation.Animation. You can also use Drawable shapes and draw them directly. Finally, if you want a simulation then you will have to look into threading. Basically you will create a timer to update the canvas for you based on an interval. There are some other view canvases you can use as well like the GLView canvas.

Categories

Resources