このXMLコードを見てください。
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:isScrollContainer="true"
android:scrollbarStyle="outsideInset">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageButton
<!-- Some Code -->
/>
<ImageButton
<!-- Some Code -->
/>
<ImageButton
<!-- Some Code -->
/>
</TableRow>
</TableLayout>
私のデバイスでは3つのImageButtonが正しく表示されています(厳密に中央化されています)。しかし、もっと大きな画面の別のデバイスでアプリをテストすると、3つの画像が左に揃っているように見えます。
レイアウトを一元管理する方法はありますか?画面の幅はどうでもいいですか。
回答:
回答№1は1私はあなたの問題を正しいやり方で理解していれば...
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:isScrollContainer="true"
android:scrollbarStyle="outsideInset"
android:gravity="center_Horizontal|Center_Vertical">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_Horizontal|Center_Vertical"
>
回答№2の場合は0
同様の形式ですべての画像ボタンをlinearlayoutでラップします。各線形レイアウトの重力を中心に設定します。すべての線形レイアウトに対してレイアウト幅= fill_parent。