I am building a quite complex layout which represents the following structure:
It has the following Layout XML:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/Button01"
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.1"
android:text="L" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M" />
<Button
android:id="@+id/Button03"
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.1"
android:text="R" />
</LinearLayout>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="--------------------" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="100"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/Button05"
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.1"
android:text="L" />
<Button
android:id="@+id/Button02"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M" />
<Button
android:id="@+id/Button04"
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.1"
android:text="R" />
</LinearLayout>
</LinearLayout>
Now i need to nest this piece several times like this:
The Structure was even more complex in the past and caused a Stack Overflow on the 3rd nested Level due to the Call Stack Size of 8/16 KB. The Current Layout can handle 12 nested Levels without Overflow but the Measuring Times are extremely high (ANR also) because i am using nested weights:
Measuring Time in msec: from Parent to Child
2000 1950 970 1200 500 500 240 245 135 120 70 70 35 45 21 15 8 8 4 3 1 1 0.3 0.01
- Is there a way to flatten the Hierarchy even more?
- Is there a way to get rid of nested weights?
- Measure in a seperate thread and Display a waiting circle in the mean time -> how?
- Call parent.addView from a seperate thread and do the whole work in a thread to prevent Stack Overflows.. which will appear somewhere beyond the 12 nested Levels. How to implement this? it was already mentioned here: Android: Increase call stack size