I have an Android 3.0 Application for Tablets. On this application I have to insert several ViewsGroup on a layout, and each of these ViewsGroup has several views.
Here is the onCreate code of the Activity:
setContentView(R.layout.main);
params = new LayoutParams(500, 600);
ViewGroup v1 = new Bar(this);
this.addView(v1,params);
ViewGroup v2 = new Bar(this);
this.addView(v2,params);
This Bar class extends ViewGroup, and has several views inside it. The problem is that only the Views of the first ViewGroup (v1) are being shown on the screen. But I can see that it add both ViewGroup to the content, since for example I can set the background of the second one and i will see the results. But the Views that are inside the second ViewGroup are not being drawn on the screen. I tried to change the order, v2 first, and all views inside v2 got drawn while the ones in v1 didn’t. I think it may have some to do with the onLayout method inside the Bar class, which I’ll put below:
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
for(int nI = 0; nI < this.getChildCount(); nI++){
this.getChildAt(nI).layout(arg1, arg2, arg3, arg4);
}
}
Does this method has any problems?
I’ using a LinearLayout by the way.
<LinearLayout android:background="#C6D7D2" android:orientation="horizontal" android:id="@+id/container" android:layout_width="wrap_content" android:layout_height="wrap_content"> </LinearLayout>
You should override onMeasure() also. You need to set the setMeasuredDimension(w,h) there. w and h are bar’s height and width that you get after adding all its childrens dimensions.