這裏你是我的問題:我想要做的佈局看起來像這樣的網格,安卓的Android tablelayout和按鈕調整
爲了做到這一點,我已經創造了這個佈局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3">
<Button
android:id="@+id/clientimain"
android:layout_width="0dip"
android:layout_weight="1" android:layout_height="fill_parent"/>
<Button
android:id="@+id/button1"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3" >
<Button
android:id="@+id/button2"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button"/>
<Button
android:id="@+id/button6"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3" >
<Button
android:id="@+id/button3"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button"
/>
<Button
android:id="@+id/button7"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Button"
/>
</TableRow>
</TableLayout>
</RelativeLayout>
所以基本上它是由6個按鈕在表格佈局中設置正確的重量屬性(或者我希望如此!)。結果看起來不錯,直到我嘗試設置每個按鈕的背景屬性。在這種情況下,按鈕將放入圖像的高度(寬度可以)。舉例來說,如果我設置背景圖片,其尺寸爲96PX X 96PX的結果是這樣的:
是否有辦法防止這種按鈕「拉伸」,並正確中心的形象呢? 我試着改變每個表格行的高度屬性,改變按鈕的最大高度屬性,也用圖像按鈕更改按鈕類型(並設置與想要的圖標src屬性),但我沒有完成通緝結果。
我也紅了有關支持多個屏幕和每個基本佈局的谷歌文檔,但我沒有找到任何解決方案。 在此先感謝任何願意幫助我的人!
安德烈
嘗試在按鈕上使用android:scaleType =「fitXY」。也嘗試和使用http://developer.android.com/resources/tutorials/views/hello-gridview.html這項任務 – 2012-02-09 23:15:56
我試過屬性android:scaleType =「fitXY」,但它沒有奏效。如果我找不到解決方案,我會嘗試切換到網格佈局。謝謝 – jiraya85 2012-02-09 23:29:24