0

私はできる限りのことを試しましたが、これは実際には不可能だと思い始めています。

私が探しているのは、幅に基づいた(水平)LinearLayout内のN個の子の動的分布です。HTMLテーブルのように、列幅を動的に計算します。基本的に、ListViewを動的に計算された幅のテーブルに変換したいと思います。

<table class="ListView">
  <tr class="LinearLayout"><td class="TextView">John:</td><td class="TextView">123-456-789</td></tr>
  <tr class="LinearLayout"><td class="TextView">Mike:</td><td class="TextView">321-654-987</td></tr>
  <tr class="LinearLayout"><td class="TextView">Sally:</td><td class="TextView">789-456-123</td></tr>
</table>

Androidでそのようなことをするにはどうすればよいですか?覚えておいてください、私はそれを2つの同じ長さの部分に分割したいだけではありません。列幅を決定し、LinearLayout全体を埋めるためのコンテンツが必要です。このように(子要素が2つしかない場合):

[ [--TextView--] [--------TextView--------] ]
4

3 に答える 3

1

を使用することはできませんLinearLayout。wrap_content`TableLayout内のすべての要素でa を使用する必要があります。TableRow' having width表示する行数が動的である場合は、ViewGroup に動的に行を作成して挿入する必要があります。それ以外の場合は、静的データに対して非常に簡単です。

于 2012-08-25T02:29:45.117 に答える
0

私はあなたがこのようなものを探していると思いますか?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:weightSum="100" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="This will take up much more space"
            android:layout_weight="20" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="test"
            android:layout_weight="80" />
    </LinearLayout>

</LinearLayout>

それはどのように見えるでしょうか。

注:「これはより多くのスペースを占有します」の背景は灰色です。これは、TextView の全長が表示されるように、その TextView にマウスを合わせながらスクリーンショットを撮ったためです。

于 2012-08-25T01:50:22.267 に答える
0

inandroid:layout_weight="1"のすべてに設定できますが、重みを使いすぎるとパフォーマンスが低下します。TextViewTableRow

于 2012-08-25T01:23:55.740 に答える