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.