どのように私は、ビューは私のAndroidアプリで自分の親の全幅を埋める作るのですか?

StackOverflow https://stackoverflow.com/questions/2405614

  •  18-09-2019
  •  | 
  •  

質問

私は、私の活動のいずれかに定義された以下のレイアウトがあります:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
    <TableRow android:id="@+id/TableRow01" android:layout_height="wrap_content" android:layout_width="fill_parent">
        <EditText android:text="Resource Name" android:id="@+id/ResourceName" android:lines="1" android:isScrollContainer="false"></EditText>
    </TableRow>
    <TableRow android:id="@+id/TableRow02" android:layout_height="wrap_content" android:layout_width="fill_parent">
        <Button android:id="@+id/Tile" android:text="Tile"></Button>
    </TableRow>
</TableLayout>

レイアウトはほとんど正しくレンダリング、唯一の問題は私のテキストボックスと私のボタンは、それぞれの列の全幅を占有していないということです。

私は、レイアウトの幅プロパティのfill_parentを指定しようとしましたが、無駄に、彼らはまだだけで、画面の約半分を占めています。

Androidのための総合的なドキュメントは、これまで偉大でしたが、私は目に見えない壁にぶつかるこのようないくつかのシナリオがあります!すべての助けをありがとう!

役に立ちましたか?

解決

やいままであなたがストレッチしたい列のインデックスです(あなたがandroid:stretchColumns="0"を定義する場合)TableLayoutを使用してみてください。

詳細について - http://developer.android.com/ガイド/チュートリアル/ビュー/ハローtablelayout.htmlする

他のヒント

あなたのTableRowビューでandroid:layout_width="match_parent"を使用します。

これであなたにパラメータandroid:stretchColumnsをSETINGあなたのTableLayoutで異なる可能性があります:

Value "*"ビューは同じ幅を有し、同じ空間を占有する行を充填する

Value "0" or other integer - >まずまたは行を充填する行の整数に対応する要素。他のビューはwrap_contentのと同じように幅を持っています。

2つの望む3のTableRowのtablelayoutと例各

設定android:stretchColumnsなします:

[|TextView|EditText|          ]
[|TextView|EditText|          ]
[|TextView|EditText|          ]

アンドロイド:stretchColumns = "*"

[|  TextView    |  EditText  |]
[|  TextView    |  EditText  |]
[|  TextView    |  EditText  |]

アンドロイド:stretchColumns = "0"

[|    TextView      |EditText|]
[|    TextView      |EditText|]
[|    TextView      |EditText|]

アンドロイド:stretchColumns = "1"

[|TextView|      EditText    |]
[|TextView|      EditText    |]
[|TextView|      EditText    |]

あなたのTableRowの定義でこれを試してください:

<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top