0

このコードの何が問題になっていますか?このテーブルの行でボタンが正しく表示されないのはなぜですか?

<TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            >
        <TableRow>
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/str1"
                    />
            <EditText
                    android:id="@+id/id1"
                    android:layout_width="70dp"
                    android:layout_height="wrap_content"
                    />
            <Button
                    android:id="@+id/id2"
                    android:layout_width="wrap_content"
                    android:layout_height="65dp"
                    android:text="@string/str2"
                    android:gravity="right"/>
        </TableRow>
</TableLayout>
4

2 に答える 2

4

TableLayoutでandroid:stretchColumns = "1"を使用して、EditTextがボタンを右に押すようにする必要があります。

または、tableRowのビューでandroid:layout_weight属性を使用して、それに応じてスペースを分散することができます。

また、TableRowのビューで幅と高さの属性を指定する必要はありません。

<TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:stretchColumns="1">
        <TableRow>
            <TextView
                android:text="@string/str1"
                />
            <EditText
                android:id="@+id/id1"
                 />
            <Button
                android:id="@+id/id2"
                android:text="@string/str2"
                />
        </TableRow>
    </TableLayout>
于 2011-06-07T18:26:52.027 に答える
3

android:gravity="right"内のテキストに使用されますButton。幅がに設定されwrap_contentているため、効果はありません。

android:layout_gravity代わりに使用する必要があります。参照:http ://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#attr_android:layout_gravity

子供が親に供給できる標準重力定数。ビュー(x軸とy軸の両方)を親ビューグループ内に配置する方法を定義します。

次の定数値の1つ以上(「|」で区切る)である必要があります。

(...)

right 0x05サイズを変更せずに、オブジェクトをコンテナの右側にプッシュします。

于 2011-06-07T17:54:02.197 に答える