Children not clickable outside parent view - android

I have a created a mapview with markers on it.
Looking at this picture below:
Grandparent is a filling View
Parent is my MarkerView
Child is a marker which is clickable
Parent has clipChildren(false) and thus the children are visible.
My problem is that the children are clickable, except for the part where Child 2 is outside the Parent.
Parent also has the appropriate TouchDelegate (and I also tried this for the children).
How can I make the complete child clickable?

I couldn't make it work without changing the elements.
I ended up enlarging the parent and using setTranslationY for the markers to keep them in place like this:

I had a similar issue and fixed it by setting app:elevation="XXdp" to the child.

The reason why you can't do this is that the default implementation of ViewGroup#dispatchTouchEvent(MotionEvent ev) iterates over the children (not the grandchildren) to look for a child that are a target (is on bottom of the click event point) and can receive touch events. It will find nothing if you touched the part that it is outside the bounds of Parent, which is the only child of Grandparent. If it does not find Parent, Parent will never be able to make a look up on its children (Children 1 and Children 2) and eventually dispatch the event to Child 2.
So you either increase the size of Parent (as the acceptable answer), which is the most easy way, or you will have to override the method ViewGroup#dispatchTouchEvent(MotionEvent ev) of your Grandparent to make a more complex lookup, like looking up grandchildren too. The method is already fairly complex, if anyone finds a implementation, please share because I don't have one.

Related

Scrollview jumps/repositions when trying to scroll on a clickable child of it

I am using two (embedded) ScrollViews like suggested here, in order to create a '2D Scrollview'.
I add multiple childs to this view, and to some of them I set OnClickListener (I also tried with OnLongClickListener as well).
Functionally the result is what I have expected, although if I try to scroll (starting from a child, that has either of the listeners), the scrollview jumps/repositions to the ~opposite direction, I started the scroll to. So if I scroll like this e.g. upwards, the view jumps a big downwards so that I can scroll up at most to the original position.
I have been trying to play around with calling setFocusable(false) on the childs and setFocusable(true) on the ScrollView(s) (but also tried different permutations of it, as I am not sure about setFocusable()), but couldn't really get on top of it.. Any suggestions?
Just encase you are still wondering this is happening because when you start scrolling the other scroll view, ACTION_CANCEL is posted to the on touch method of the original ScrollView which causes a default scroll view to jump back to its original position.

Android Modify Parent View after Child is Drawn

I am having issues with modifying a parent view after a child is drawn. I need data from the child after the onDraw method is called. I need to use this information to modify the parent view. So after the child is drawn, how would I go about modifying the parent view (drawing on its canvas)? I'm sorry that I don't have code, but I don't know how to implement what I'm asking (thus the question). Is this possible? Any help is appreciated.
All,
I took your advice Vee and I ended up doing everything in the child. Its not pretty, I basically grab the parent and traverse through the children getting the parameters that I need... So, that is the solution that I used. Just when you are rendering the child you can reference the parent and then pull all the information you need.

Is it safe to draw a view that was not added to the view group using addView?

I am trying to draw a View in a ViewGroup without adding it to the child list.
I am doing this because I want to display something like a ProgressBar in the exact center of layouts like a LinearLayout so I don't want the layout to handle the measuring and layouting.
I also don't want to complicate the view hierarchy by adding extra layouts just to achieve this effect so my solution was to extend the LinearLayout, create a ProgressBar and handle measuring, layouting and drawing for that view myself.
My implementation seems to work ok from what I tested but I am wondering if there is anything I am not noticing or if there are any problems that can appear in the future.
From what I understand calling addView also sets the child view's parent and calls dispatchAttachedToWindow, these methods are package-private so I can't call them myself.
Is there any side effect that can arise from calling measure, layout and draw on a view that has no parent and that was not "attached" to a window? Is there a safer way to achieve the same effect?
Thanks.

Child view move out from parent view and does not respond to pressing, Android

After animation button moves out from parent layout and does not respond to touch. I tried to use TouchDelegate for extending a view's touchable area, but it did not work in my case. I need it to scale (parent layout with all childs), and I do not want to change the size parent layout. Whether it is possible to solve this problem?
thear scheme of problem
I use TouchDelegate for Parent view and check window location coordinate for child views. When there is a pressing on the ParetView, I check to see if in the same place a childView, and if so, then move it.

How to restrict bounds for Translate Animation for a view in Android?

Let me explain the scenario that I want to achieve:-
Consider the below as the Layout I have inside a Parent_Linearlayout:
[Linear Layout] (Fill_Parent, Wrap_Content)
[ScrollView]
Activity's setContentView is set to the Parent_Linearlayout
In the application, when a condition is met, I want the Scrollview to be removed from the screen and instead put another View in its place.
I've been able to do this, & when I remove the ScrollView, I'm applying translate Animation to it so that it seems as if the View has gone to the top -before removing it.
But when the animation occurs, the ScrollView translates OVER the Linear layout present above it.
How do I restrict it, so that the scrollview does not go over the linear layout, but disappears at the base of the Linearlayout. I want the linearlayout to always stay visible..
I've been trying to do this from quite some time, but I've not been able to get desired results..
Could someone kindly help me out here??
I don't quite understand your description of your layout, but the Android view system is drawn based on the ordering of the views in the hierarchy. Views added later to a parent are drawn after those added earlier. So if you always want the LinearLayout to be drawn on top of the ScrollView if/when they overlap, then declare or add the ScrollView object to its parent before the LinearLayout object.
In thinking more about this, I suppose the ordering here is important because you want the ScrollView to be placed below the LinearLayout in the parent of both of these views. Putting the ScrollView first (and thus having it painted first) would then put it above the other LinearLayout, which isn't what you want.
There are various ways to achieve what you want. For example, you could use a RelativeLayout as the parent of the views, then the ordering is not important.
Alternatively, you could place the ScrollView inside another LinearLayout (and that LinearLayout would be the second child of the overall parent layout). Then when you animate the ScrollView, it would be clipped by its immediate parent, which I believe would give you the effect you're looking for (make sure that setClipChildren() is set to true on this new intermediate LinearLayout, which it is by default, otherwise it won't clip the ScrollView as it animates out of it). Note that this approach would necessitate different animation values, since you are now animating the view outside of its parent (the new LinearLayout).

Categories

Resources