How to add view on imageView? - android

I have created a class that extends a view which will work as a drawing slate to draw a text. I want to add that drawing slate in image View. And I have main activity which contains a scrollable list on top and a image view below list. Now I want to add that View(Drawing slate) on image View. So how to implement this? I tried lot, but I am not getting how to do this.Do i need to use any other view instead of image View? Please help as soon as possible. Thanks in advance.

just extend ImageView and do your drawing in onDraw method, make sure you call super.onDraw()

Related

Drawing a custom shape to load Image as recyclerview item

I want to make a custom layout like below view.
In this view I want to make TextView half sliced from one end and another ImageView from another end. So please tell me how to make such custom TextView and ImageView with diagonal clipped from one side.
With reference from this answer you can use this view and customize it horizontally instead of vertical.
Or you can also check for this code as well which something like below image.
Reference also available here

Determine if view was invalidated (changed)

How I can determine if a view was invalidated? I see that the View class has isDirty() method but it doesn't seem to work in my case.
I'm making a custom layout that can animate blurring of it's content. It extends FrameLayout. So at first the layout draws it's first child to a bitmap, and than displays the bitmap instead of actual view. Also it starts AsyncTask that creates blur animation steps.
So I need to know when the child view was changed so I can redraw the bitmap and restart AsyncTask.
I've found that this can be implemented using ViewTreeObserver.OnPreDrawListener

Android Best way to overlay an item in an ImageView

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.

In android, can I add child views to an ImageView?

I have a layout which contains a ScrollView which contains various components including an ImageView. I've found that I can add a TouchListener to the ImageView and the x,y values I get for the event are offset from the corner of the ImageView (including padding). Thus I can easily handle touch events without worrying about the state of the ScrollView.
The problem is that I don't see a way to add a view on top of the ImageView so that I can make a visual change to the ImageView when it's touched in certain locations.
Specifically, there are various boxes in the image which I'd like to highlight when they're tapped. I can add a view to the activity, but I'd have to take the state of the ScrollView into account in order to display things in the right spot.
What's the best way to approach this? Can I derive a new version of ImageView, overload the draw method, and use that somehow? (not sure how I'd specify it in the xml, I'd probably need to set it in the onCreate of the activity)
You should be able to override the onDraw method of the ImageView as you suggested and draw stuff on top of the ImageView. The onDraw method gives you the Canvas that you could draw on. In the XML, you could just use the name of the new class you created instead of "ImageView" (unless you want to add parameters in addition to the ones offered by ImageView, this should be pretty straight forward).
<your.new.awesome.class.with.the.full.namespace
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/awesome_image_view"
/>
The problem is that I don't see a way to add a view on top of the ImageView so that I can make a visual change to the ImageView when it's touched in certain locations.
It seems that you are more comfortable with having a separate view that you could work on. You could do that by encapsulating the ImageView with a FrameLayout and then adding another view of any kind as a sibling of that ImageView. This view would be drawn on top of the ImageView if it was mentioned in the FrameLayout after the ImageView. This solution may not be the most efficient one, but it might get you started. Overriding the onDraw method of the ImageView would definitely be the best option.
you can make a relativelayout or something with a background as your desired image instead of having just an imageview. then you can have child views within that relativelayout.

android custom view how to draw button on top of the view

I am creating a android app using LunarLander as a example.
Now I need to create a few buttons which are drawn over the view.
I do not want them as a seperate layout above or below the view but in the custom view.
Is this possible or am I going to have to programmatically show the button images then detect the touch. The buttons I create using new never show on the app. I assume this is because I have overwritten the onDraw and the buttons are never drawn even though I call
super.onDraw(canvas);
I think you could use FrameLayout to show two layers - first would be your surface from lunar, and second is the layout with buttons etc. You could define everything in layout.xml file. Probably that is enough.
Regards!
If your view extends Linear/Relative/TableLayout, you can use view.bringChildToFront(child).
Use AbsoluteLayout & then in your ui thread set button.bringTioFront() & you are done!
watch this post Problem when using more elements in the ListView

Categories

Resources