detect which part of image is clicked - android

I want to make an app in which I ll show a human body. when we click on any body part the organ name should be displayed with a toast. How will I detect which body part is selected. According to me i ll make small images for every organ. and place those images behind the main image. Is it the right way? How will I draw organs(Bitmaps or png images?).

I think an easier way to do it is to draw shapes or even buttons over your image, and define them as transparent so you don't see them. Then, using onClickListener you can capture what button is clicked and do whatever you want.
Check this for an example

Related

Android - Choosing a option shown by circle shaped touch objects

I have provided a picture below so you can get a better understanding. Basically I want the user to pick a number from 1-10 which is shown by circles (Only 1 number can be picked at a time). Lets say I pick number 10, as you can see on the picture I want the circle to stroke and change the color when the number is picked (indicating to the user that the number has been chosen). After the number is picked and you press the "blue button", I want to get the value picked to do other calculations.
This is how I want it to be
I feel having a touch based circle is the best way to do it, rather than using a spinner because it take more time. Now the question is how to do this without code duplication or redundancy and how to achieve this in the best way possible. I am thinking I have to create a circle object (Possibly button shaped like circles) 10 times and put text on them, group them in array?..etc or is there a more efficient way to do this.
I'm sure there's better ways to achieve this but I suggest a simple solution as you wanted !!!
Now the question is how to do this without code duplication or redundancy?
You can create a xml file in your drawable folder and put two different oval shapes in that: defaultShape and pickedShape, Use <solid> and <stroke> tags to customize your shapes as you like, and then apply it to your buttons' background.
In order to handle the picking of your button you should implement same onClickListenerfor all 10 buttons, if one of them is picked save it to a temp variable like Button pickedButton, in your listener your check if pickedButton is not null change its background to defaultShape, and assign the new picked one to the pickedButton and then change its background to pickedShape.
Hope you find it helpful.

set up different clickable part image android

Im working with android about image and onclick listener. The purpose of my app is to monitor the area that user clicks on the screen. For example, I have a picture containing a rectangular and a circle. Assume that the color of the whole picture is brown(wood). So when I click on the rectangular, the color of rectangle will change to yellow. When I click on the one part of the picture, the color of that part will change its color, but other parts do not change. So, Im thinking about the solution for this app. Do I have to cut this picture separately and put them into the screen by using relative review? Or is there any other way to do this(Set up a coordination system)?
Yes you have to cut this picture separately and put them into the screen by using relative review. For example two ImageView with your backgound.
You can slse the image as recommeded by the other post, or overlay the image with a RelitiveLayout with specific sized buttons (background = #android/color/transparent)

How to add dynamic text entered by user to canvas in android?

I am making an app in which a user enters some text and that text has to be displayed on a rectangle on an image(like a notes-stick on the image, it can be dragged on the image and also re-sized). I am very new to android and i really can't find a way to do so in android through books and google.
I have been designing apps using html, in html we could just style a text-box like we want and add it anywhere on the page. But here i am unable to configure the edit-text to do the same. But i am unable to make the edit-text like a notes-stick and to make it draggable and re-sizable dynamically.
I also tried drawing just a rectangle using canvas.drawrect() ... but how to add text to that dynamically is something which i am unable to figure out.
I am not asking for the entire code ..but please guys give me a head-start to the right direction so that i can try things out and try to figure out a way.. Right now i am badly stuck.
The image below shows how the notes-stick should look like...
If you don't need it to be actually drawn on the canvas itself, using an EditText widget and having both it and your image in a RelativeLayout may be the way to go. You can set max height and width of the EditText, or have it wrap the height so it expands with the text, etc. Just make sure that the EditText widget gets added to the RelativeLayout after the image, so it is on top.

Identify portions of image which is to be shown in ImageView

I have got an image with different arbitrary shaped portions in it.
Now I want to show some data when clicked in the particular portion of the Image. e.g. When I click in the portion A, I want to show a notification with name of the portion.
I don't have idea on how to achieve this task. Please guide me on this.
Try to add an OnTouchListener to get the coordinate where your image gets touched. With these coordinates you could match the shape what is clicked.

Android writing over image in button

If I have a custom image can I write over it, will it always write to the center of the button image? Ie will setText on image always right to center of the image provided or do I need to do something to have this effect? Thanks Also is it better to use ImageButton or set Image as background of Button? and write over it that way. I want to use 3d images and write on top of them in black text.
I don't know if there is a preformance difference for using image button of a normal button, but I'd imagine that and image button will work better. Albiet I always just use a normal button and setBackground(...). Also if you want to set the text to always be in the middle, use android:gravity="center" in the layout file.

Categories

Resources