簡體   English   中英

Android表布局圖像邊距

[英]Android table layout image margin

我有以下表格布局,用於在網格中顯示圖像按鈕。

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<TableRow
    android:id="@+id/tableRow4"
    android:layout_weight="1" >

    <ImageButton
        android:id="@+id/button_one"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/button"
        android:scaleType="fitCenter"
        android:src="@drawable/button_one" />

    <ImageButton
        android:id="@+id/button_two"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/button"
        android:scaleType="fitCenter"
        android:src="@drawable/button_two" />
</TableRow>

<TableRow
    android:id="@+id/tableRow4"
    android:layout_weight="1" >

    <ImageButton
        android:id="@+id/button_three"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/button"
        android:scaleType="fitCenter"
        android:src="@drawable/button_three" />
</TableRow>

如您所見,第一行包含兩列,第二行包含一列。

我希望圖像能夠擴展以適合表格單元格。 底部的圖像按鈕的邊緣與頂部的兩個圖像按鈕不太對齊。 好像底部單元格上有多余的填充或邊距。

任何想法如何使它們完美排列?

提前致謝。

屏幕截圖:

在此處輸入圖片說明

如vasart所述,將所有fitCenter替換為fitXY fitCenter解決fitXY

更新的XML:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff" >

    <TableRow
        android:id="@+id/tableRow4"
        android:layout_weight="1" >

        <ImageButton
            android:id="@+id/button_one"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:adjustViewBounds="true"
            android:background="@drawable/button"
            android:scaleType="fitXY" />

        <ImageButton
            android:id="@+id/button_two"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:adjustViewBounds="true"
            android:background="@drawable/button"
            android:scaleType="fitXY" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow5"
        android:layout_weight="1" >

        <ImageButton
            android:id="@+id/button_three"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:adjustViewBounds="true"
            android:background="@drawable/button"
            android:scaleType="fitXY" />
    </TableRow>

</TableLayout>

我解決了這個問題

我本來是使用九個補丁的可繪制對象作為背景的,因為我有彎曲的角,但是當我切換到帶有尖角的常規圖像時,我卻忘記從圖像中刪除邊框了。 重做圖像解決了問題-我的xml仍然很好。

/ palmface

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM