いくつかのTextViewを保持するためにビューが必要ですが、残念ながら正確な数はわかりません。TextViewsを並べ替えるには、スタックを並べて表示する必要があります(Tetrisを想像してみてください。ただし、長方形または正方形のみを使用します)。私がそれについて考えようとした方法は、LinearLayoutを使用してそれらを水平または垂直に保持することです。次に、それらが互いに隣接している場合は、それらのウェイトを使用して適切にストレッチします。それ以外の場合は、垂直方向を使用します。問題は、より複雑なスタックを持つネストされたLinearLayoutのパフォーマンスです。私はRelativeLayoutを使用することを考えましたが、TextViewがオーバーラップしないようにする必要があるため、それは機能しません。したがって、それらが互いに隣接している場合のように、それぞれが十分なスペースを均等に取る必要があります。layout_weightを使用すると、うまく機能します。
これが私に警告を与えている例です(私がプログラムで行っていることの簡単な例だけです):
<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" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hello World 1"
android:background="#000000"
android:layout_weight="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hello World 3"
android:background="#000000"
android:layout_weight="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hello World 4"
android:background="#000000"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World 2"
android:background="#000000" />
</LinearLayout>
ちなみにRelativeLayoutで試してみましたが、TextViewの1つは設定されたサイズである必要がありますが、スペースを均等に取る必要があります。具体的なサイズはわかりません。画面の幅を測定してそのように分割することも、不格好で正確ではありません。皆様からのご意見をお待ちしております。
編集:それで私はそれについてもう少し考えていて、RelativeLayoutを使用する解決策を考えました。Androidドキュメントには良い例がありますが、唯一の問題は、ビューの1つを設定サイズにして、もう1つを拡張できるようにする必要があることです。しかし、それらすべてに設定されたサイズを持たせないようにする方法があれば、それも機能する可能性があるので、それらは伸びることができます。誰かがいつかそれをやろうとしましたか?