Lets say I have an irregular shape in png format.As you know this shape considered in an invisible square or rectangular when I defined a view (its background is sourced from this png) on my xml.On my activity,I write a piece of code which sends an alertdialog when clicked on the view.even if I click a place which has no revelant with the shape (but it is in that invisible area)I get the dialog.I want to get an action when I click ONLY shape.How can I solve ? Thanks...
Basically,
You have to find a way to correctly and efficiently model the surfaces in the PNG file.
Then you can implement onTouch(MotionEvent event) of your view to handle the motion events and match the coordinates of the touch with your implementation in the first step.
Related
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 [...]".
I have a blueprint image in my app. The user will be able to click on some pre-established points and after they click on this point, a dialog will show some information.
My question is how I add the specific points in my ImageView Blueprint and the click function on these points?
EDIT 08/08/2014
My ImageView now has pinch zoom and the app will have more than 1 blueprint.
Thanks and regards!
You could go about this multiple ways. If your blueprint is full screen on the users device then you could create your own custom layout to encapsulate the imageview and override the ViewGroup's onDraw an onTouch methods to add your points. Then you could have a method like
public void addPoints(float[] points) { // do something here }
Another option is to extend the ImageView itself and make your own custom imageview and then again override onDraw and overlay the points ontop of the image. YOu can set the bitmap (your blueprint) as the background and then drop ontop of that. You would have to figure out where the specific points are though depending on the size of your image and the device, unless you set the size to be pixel density independent.
The first thing that comes to mind is you could use RelativeLayout in the XML file. This allows you to layer elements on top of one another if you so choose. You could use this to position invisible buttons above the image.
With RelativeLayout, each button could be positioned using its margin attributes, and it should be fairly simple to make the button invisible by assigning the transparent color for its background and providing no text.
I'll need to implement a UI that reflects the layout of a real object. Below is the layout that the client wants. Each black block is a button, so it need a custom drawable, listeners, states, etc.
I'd like to use a custom implementation of the Button widget, but as far as I know they only accept rectangular touch targets and laying them out could be tricky.
What would you use to achieve this layout?
Please note: the 2 central button should be a semicircle cutted in half (with some padding between the 2), not this strange shieldy shape, I'm just not that good with Photoshop.
EDIT: As suggested in this question I could use a TouchListener on the layout and fake a click on the right button. The main problem with this solution is that I'll need to know the bounds of the drawable, not the rectangular ones of the button's bounding box (that is always rectangular). How could I do that?
I want to implement a application in this application multiple click event like periodic table i want to use large image for this and make image clickable from its different different part called element in this implementation zoom and scroll feature are also include
Try this:
Define a Rect for the spot/area that you would like to make clickable. Also remember to redifine it based on screen layout size and resolution.
Now onTouch event get the x and y position and calculate whether it lies within the defined Rect and act accordingly. The Rects will act as virtual image maps.
I think you have to divide your large image into sub images and add these sub images to every image view. You have to create a layout such that all these image views must show the original large image without any disturbance at corners, then only you can get separate click events for each sub image.
I think that this is a good idea.
Use a "layer" with different alpha level areas. Each area with a specific alpha level is a specific action-click.
https://groups.google.com/d/msg/android-developers/_6u3Iu-sYrI/DA0KCo8pTksJ
I want to create a circle layout. All of my views should be in the circle. Which layout do I have to prefer and how? The focus of the layout should be a clockwise circle.
Edit:
I can do this view and it is an update of my question, prompted by the comments to this question. Is there any example for doing that?
The screenshot is attached below.
image http://www.freeimagehosting.net/uploads/e11f35e522.png
For people who is coming to this question now I recently had to implement this circle layout and after a lot of searching I decide that a relative layout that draws a petal shaped buttons will not give me the effect I needed so I followed those steps
you can see if you tested the nbc app on iphone they are placing invisible buttons on the words and the circle is just an image with the button overlaid but I didn't like this solution .
So here's how I implemented it
1- asked for the flower with the words on it from the UI guy and told him that the colors must be solid no gradient what so ever and then asked him to send me the hexadecimal values of each color.
2- then I implemented a motion listener that checks the color of the pixel the user clicked on ACTION_UP event and launch the event corresponding with the category of that color .
3-I check the color by getting x & y from the listener and then get the color from the image bitmap
I'll post snippets of the code If anyone needs it but I don't have it on me now.