0

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() で動的に出力しました...、常にまったく同じになります。

4

1 に答える 1

0

この問題が発生しました。代わりに相対レイアウトを使用する必要があります...それでもテーブルレイアウトを使用したい場合は、次を試してください:

TableLayout tableView = (TableLayout) findViewById(R.id.tableView);
TableRow row = (TableRow) inflater.inflate(R.layout.tablerow, tableView, false);
ImageView imgDis = (ImageView) row.findViewById(R.id.spinnerEntryContactPhoto);
    imgDis.setPadding(5, 5, 5, 5);
    imgDis.setAdjustViewBounds(true);

    // set row height width

TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 50);

    params.topMargin = 0;
    params.bottomMargin = 0;
    params.leftMargin = 0;
    params.rightMargin = 0;

この助けを願っています

于 2013-06-24T11:13:09.170 に答える