I am creating an Android application. I want that when my Parent is ready to be drawn, it collects its children's views from a function. I am doing it because my children's views are being refreshed dynamically. On each refresh, I am invalidating my Parent's layout.
class Parent extends RelativeLayout
{
protected void onDraw(Canvas c)
{
View view = getComposeView();
// create layoutparams depending upon scroll/zoom level of parent
addView(view, layoutparams);
}
}
// In some other class
View getComposeView()
{
//
return view;
}
void refreshViews(View newView)
{
setComposeView(newView);
getParent().invalidate();
}
I observed that calling addView in the onDraw method triggers onDraw repeatedly. Is there a way I can add my view to Parent in its onDraw method? The reason I wanted to add it in onDraw is because when I scroll/zoom my Parent, it automatically calculates updated layout parameters of my child view in its onDraw method