我正在嘗試創建一個帶有6個按鈕的佈局,這些按鈕可以自動適應屏幕大小,如同windows phone的tile一樣。在代碼中,我動態創建6按鈕,2爲線條,但按鈕應該適合填充後者的屏幕大小。我該如何繼續?如何使用6個按鈕創建佈局,如窗口瓦片
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/conv_up" />
<Button
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/conv_up"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/conv_up"
/>
<Button
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/conv_up"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/conv_up"
/>
<Button
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/conv_up"
/>
</LinearLayout>
把你現在看到的,以及你的期望。否則將很難回答。 – Siddharth 2013-05-09 18:26:44
我看不到任何東西,因爲此代碼給我這個錯誤:「可疑大小:這將使視圖看不見,應與layout_weight一起使用」在LinearLayout上android:layout_height =「0dip」 – bisemanu 2013-05-10 08:05:04
「0dip」是問題。 – Siddharth 2013-05-10 08:42:48