Alternative to LinearLayouts' layout_weight attribute?
<p>I need a View to hold a number of TextViews, and the exact number I will not know unfortunately. I need the TextViews to sort of stack either under each other or right next to each other (imagine Tetris, but with just rectangles or squares). The way I have tried thinking about it is using LinearLayout to hold them either horizontally or vertically. I then use their weights to stretch them appropriately if they are next to each other. Otherwise, I use a vertical orientation. Problem is the performance with nested LinearLayouts with more complicated stacks. I thought about using RelativeLayout, but that wouldn't work because I need the TextViews to not overlap. So like if they are next to each other, they need to each take enough space evenly. With layout_weight it works great. I was hoping someone had any idea on how to make this work right/alternative.</p>

<p>Heres an example that is giving me a warning (only a simple example of what I am doing programmatically):</p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" &gt;
&lt;LinearLayout 
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_weight="1"&gt;
    &lt;TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Hello World 1"
        android:background="#000000"
        android:layout_weight="1"/&gt;
    &lt;TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Hello World 3"
        android:background="#000000"
        android:layout_weight="1"/&gt;
        &lt;TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Hello World 4"
        android:background="#000000"
        android:layout_weight="1"/&gt;
&lt;/LinearLayout&gt;
&lt;LinearLayout 
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_weight="1"&gt;
    &lt;TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hello World 2"
        android:background="#000000" /&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p></p>

<p>I've tried it with RelativeLayout by the way, but one of the TextView's needs to be a set size, but I need them to take space evenly. I won't know specific sizes. Measuring the screen width and dividing it that way is also both clunky and not precise. I appreciate anybodies input.</p>

<p><strong>Edit:</strong> So I've been thinking about it some more and thought of a solution using RelativeLayout. There is a nice example in the Android <a href="http://developer.android.com/guide/topics/ui/layout/relative.html" rel="nofollow">docs</a>, but the only problem is one of the Views needs to be a set size so the other one could stretch. But if there is a way to allow all of them not to have a set size, that could work too, so then they can stretch. Anyone tried doing that at some point?</p>
