我在使用Table布局时遇到问题,导致ImageButtons在网格3x4中均匀分布。下面是使用代码来实现这一点。有fitXY(图像在水平或垂直方向不自然地拉伸)。我在最后一行中的fitCenter图像不是正方形,与其他图像相比看起来很奇怪(所有图像都是正方形)。最后一行中的这些图像水平变窄。
*我也有疑问TableLayout和weight =" 1" + match_parent每个地方和如果一个图像将具有100x100px和其他400x400px我注意到这个常规网格完全搞砸了。实现这种常规按钮网格的最佳做法是什么? *
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bigben"
android:id="@+id/moreappsSwipeLayout">
<TableLayout
android:id="@+id/MoreAppsActivityTable"
android:layout_above="@id/swipe_instruction"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginTop="80dp"
android:layout_marginBottom="80dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp">
<TableRow android:id="@+id/TableRow01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageButton
android:id="@+id/downloadEnglishBtn"
android:contentDescription="@string/english_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/en_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
<ImageButton
android:id="@+id/downloadSpanishBtn"
android:contentDescription="@string/spanish_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@+drawable/es_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
<ImageButton
android:id="@+id/downloadGermanBtn"
android:contentDescription="@string/german_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@+drawable/de_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
</TableRow>
<TableRow android:id="@+id/TableRow02"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageButton
android:id="@+id/downloadFrenchBtn"
android:contentDescription="@string/french_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@+drawable/fr_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
<ImageButton
android:id="@+id/downloadItalianBtn"
android:contentDescription="@string/italian_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@+drawable/it_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
<ImageButton
android:id="@+id/downloadPolishBtn"
android:contentDescription="@string/polish_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@+drawable/pl_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
</TableRow>
<TableRow android:id="@+id/TableRow03"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageButton
android:id="@+id/downloadPortugueseBtn"
android:contentDescription="@string/portuguese_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@+drawable/pt_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
<ImageButton
android:id="@+id/downloadRussianBtn"
android:contentDescription="@string/russian_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@+drawable/ru_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
<ImageButton
android:id="@+id/downloadDutchBtn"
android:contentDescription="@string/dutch_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@+drawable/nl_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
</TableRow>
<TableRow android:id="@+id/TableRow04"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageButton
android:id="@+id/downloadRomanianBtn"
android:contentDescription="@string/romanian_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@+drawable/ro_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
<ImageButton
android:id="@+id/downloadTurkishBtn"
android:contentDescription="@string/turkish_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@+drawable/tr_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
<ImageButton
android:id="@+id/downloadArabicBtn"
android:contentDescription="@string/arabic_lang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@+drawable/ar_favicon"
android:background="@null"
android:layout_margin="6dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
</TableRow>
</TableLayout>
<TextView
android:id="@+id/swipe_instruction"
android:text="@string/swipe_instruction"
android:textColor="#000000"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="40dp"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>