I want to place some (a variable number of!) buttons in a circle around a button in the center. It should be flexible enough that I can easily add one button more in the circle or remove one.
I'd also maybe like to add some animation in the future: the buttons should appear from one side and then circle around the button in the center.
It would be extremely easy to implement but android somehow doesn't allow to set absolute positions.
I mean I can easily calculate the positions where the buttons should be on the circle but how can I the place them there?
By the way, I don't want to add the buttons dynamically they are already on the view (wie View.INVISIBLE).
thanks for your help
Related
At the start I want the user to see:
The then want to give the user the choice to be able to drag H or C into the circle, so that it looks like:
This means while the user drags the H into the circles the other items that are already in the circle are have to move to make space for it. Ideally I would want them to be evenly distributed in the bigger circle. To have a nice UX I want the transition between the two images to be visible.
How do I best implement this UI?
the best way to do this is you use separate overlapping imageview to construct the big image and use separate imageview for each part image. then use imageview.setOnDragListener() for drag image and imgview.setOnTouchListener() to create shadow. study about this and you will definitely do it.
I dont know how to achieve this effect on long click. Long click on image in pinterest android app. Three buttons sliding from red ring to left.
Edit: like this https://github.com/GnosisHub/GHContextMenu
Put 3 invisible ImageViews in the layout (these are the buttons). Set an onLongCLickListener on the larger ImageView. When the long click occurs, make the three buttons visible and animate them into position with ObjectAnimator or ViewPropertyAnimator. When you want to dismiss the buttons, animate them back to where they started and make them invisible again.
You will have to do some math and figure out how far to translate (move) the buttons in the X and Y directions, and it will be different for each button. I suggest placing the buttons where you want them to be when they are visible. When you want to animate them, calculate the difference between their current position and the center of the larger image (or from the touch location). Then you set translation X and translation Y to those values and animate them back to 0.
I am making a game of Gomoku in Android. I have made a grid out with drawLine(): http://i.stack.imgur.com/Mm4HZ.jpg
I am now trying to make the app detect presses within the small squares. I was thinking perhaps I could generate buttons to be in the center of each square. I have the height/width of a single square saved to varibles so getting the center points to each square shoudln't be difficult. However, how should I dynamically generate buttons where each corresponds to a certain [i][j] in a 10 * 10 matrix where the field data is stored?
You can register an onClickEvent with any view in android. What you want is an invisible view the area of the places were you want click events. I suggest using buttons or something visual so that you can see where the areas are, register the click events for each view, then hide the views so that they are invisible.
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.
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