Any ideas on how to overlay a View over an ImageView?
More specifically I would like to popover view when the user clicks in certain regions of my ImageView.
I'm solving this problem drawing the popover view after the image in the onDraw() method but it has been a pain to handle events when the user clicks in the popover.
Thanks in advance
FrameLayout resolves this problem. You can place two children inside the FrameLayout, where the first child will be the background and the second will be the foreground. Let your ImageView be in background, then you can place any other View and it will overlay the ImageView. Hope this helps.
for overlaying views, you can wrap them in a FrameLayout. add first the ImaveView to it, then the overlay view.
Related
Looking for your help. I am using constrain layout. On top of blue rectangle, I have other elements too, but not sure how to achieve the layout that I have shown in the image.
I tried using card view and text view and button inside it. Please let me know if I miss any details or some information is required. Just looking for better approach.
I tried using card view and text view and button inside it
This is fine. And you will need another layout inside CardView because CardView can only hold one child. You can use ConstraintLayout,LinearLayout, RelativeLayout... to hold your TextView and Button.
I want to attach an onClickListener to an ImageView which is made INVISIBLE. I know I could set it to the TRANSPARENT color but due to certain reasons I don't want to do that and an INVISIBLE ImageView is not listening to clicks. Is there any way to achieve the required thing?
No, INVISIBLE views don't receive touch events. However there are a few alternatives you can use:
Set the view's alpha to 0. This would make it fully transparent.
Create a 2nd view of the exact same size above the view and put the click handler on that.
Put a touch handler on the parent and check if in the area of the invisible view when you detect a click.
Least work is probably top to bottom on that list.
I have 40 ImageViews inside a GridLayout, they have different colors and I want to know if user touched the desirable image or somewhere else(for example if user touched red image). How should I do that?
Set an OnClickListener for each view and store the views. In onClick you can check the view and know what ImageView was clicked. You could also think about changing the type to ImageButtons!
If you have further problems with your Grid not being able to be clicked, check this out: http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several-clickable-areas/
TLDR: Disable focusing of the views in your layout.
If you manage your images in a collection maybe think about switching to gridview and implement an adapter with an itemClickListener. So depend on which item is clicked do you action.
How GridLayout items come from the Adapter(List/Image) in Android App
I have already created a circle with the use of a View and have not used SurfaceView at all. I want to create buttons which when clicked on show images from the drawables. But I have read on the net that a SurfaceView is required to allow UI elements to be placed on top. Is this true, can someone please help me, as I am confused on this.
Thanks.
It's not very clear what you want to do, but if you want to place UI elements on top of each other without using SurfaceView you can you a RelativeLayout, this layout allows you to have views on top of each other, do you can have an ImageView with a drawable appearing over a button for example.
If you just want to change the background/src images of a button when clicked (for example to create a 3d effect of clicking), you can check out selectors, these allows you to specify different drawables for pressed/normal states.
If you want to create buttons on a SurfaceView, I suggest you render Bitmaps that will represent buttons. You will have to programmatically check if the touch coordinates are in the bounds of that bitmap tough, to register a button click.
I hope this helps.
I have one absolute layout which contains many ImageViews. I have implemented Drog and Drop functions for all imageview. Now what happen when suppose i drag one imageview over another imageview then first view goes back side because it have been added first compaire to another one . I need that moving view always visible on top.
So can i solve this problem ?
Thanks in advance.
Probably the easiest way to avoid this is to call .bringToFront() on your ImageView when you begin your dragging code.
http://developer.android.com/reference/android/view/View.html#bringToFront%28%29