3行のTableLayoutと、各行に3つの画像ボタンを使用しています。画像の縦横比を維持したい。
次のようなレイアウトを定義しました。
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#000000"
android:padding="0dp" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="0dp" >
<ImageButton
android:layout_weight="1"
android:adjustViewBounds="true"
android:contentDescription="@string/Cell"
android:padding="0dp"
android:scaleType="fitCenter"
android:src="@drawable/empty" >
</ImageButton>
<!-- Two more images like above -->
</TableRow>
<!-- Two more rows like above -->
</TableLayout>
このレイアウトでは、次のようなものが得られます。
http://i.stack.imgur.com/reoSd.png
ご覧のとおり、最後の列の行間に奇妙な穴が開いています。理由はわかりませんが、TableLayout のマージンを 0dp に変更すると、この問題はなくなります。
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="#000000"
android:padding="0dp" >
そして結果:
http://i.stack.imgur.com/Jytix.png
なぜこの動作ですか?私が間違っていることは何ですか?エミュレーター上の多くのデバイスでこれをテストしましたが、常に同じ結果が得られました。追加情報として、最後の列と最初の列の画像のサイズとパディングを getHeight() と getWidth() で動的に出力しました...、常にまったく同じになります。