2011-03-24 52 views
0

在Android中,我試圖基本上創建一個2行的表,其中1行是10像素,另一個需要其餘的屏幕。在Silverlight中,這相當於有兩行的表格,一個在「Auto」上,另一個在「*」上。比例行大小與1固定行

有沒有辦法做到這一點?我一直在玩佈局重量,但這總是一個百分比,我想1行是固定大小(基本上wrap_content)。

任何想法?

編輯: 我試過什麼建議,但它沒有工作..所以我想第一行佔用整個空間,除了第2行佔用。第2行由兩個並排的按鈕組成,第1行只是一個ListView。以下是我有:

<LinearLayout android:orientation="horizontal" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:layout_weight="1" android:background="#FF0000"> 

    <ListView android:id="@+id/edit_group_listView" 
     android:layout_width="fill_parent" android:layout_height="fill_parent" /> 

</LinearLayout> 

<LinearLayout android:orientation="horizontal" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:layout_weight="0" android:background="#FFFF00"> 

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" android:layout_width="fill_parent" 
     android:layout_height="50dip" android:stretchColumns="2"> 
     <TableRow> 
      <Button android:text="@string/button_save" android:id="@+id/edit_group_save" 
       android:layout_width="150dip" android:layout_height="50dip" 
       android:enabled="false" android:layout_column="1"></Button> 

      <Button android:text="@string/button_cancel" android:id="@+id/edit_group_cancel" 
       android:layout_width="150dip" android:layout_height="50dip" 
       android:layout_column="3"></Button> 
     </TableRow> 
    </TableLayout> 

</LinearLayout> 

當我看到這一切我看到的是黃色的LinearLayout(按鈕),沒有列表視圖可言。該列表視圖有50個項目,我可以通過將其從此設置中刪除來確認它是否可見。

回答

0

好了,所以其實我想通了這一點通過審查什麼Taranasus寫道,這是精確到度。

這是最後的XML工作:

<LinearLayout android:orientation="vertical" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:layout_weight="1" android:background="#FF0000"> 

    <ListView android:id="@+id/edit_group_listView" 
     android:layout_width="fill_parent" android:layout_height="fill_parent" /> 

</LinearLayout> 

<LinearLayout android:orientation="vertical" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:layout_weight="0" android:background="#FFFF00"> 

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" android:layout_width="fill_parent" 
     android:layout_height="50dip" android:stretchColumns="2"> 
     <TableRow> 
      <Button android:text="@string/button_save" android:id="@+id/edit_group_save" 
       android:layout_width="150dip" android:layout_height="50dip" 
       android:enabled="false" android:layout_column="1"></Button> 

      <Button android:text="@string/button_cancel" android:id="@+id/edit_group_cancel" 
       android:layout_width="150dip" android:layout_height="50dip" 
       android:layout_column="3"></Button> 
     </TableRow> 
    </TableLayout> 

</LinearLayout> 

這個網站還幫助:http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/

的問題,表示: 1.取向必須是「垂直「,根據文檔,這實際上沒有意義。 2。第二行(固定的)必須有wrap_content的高度,這也是沒有意義的,因爲谷歌關於權重的文檔特別指出這兩個元素應該是fill_parent。

+0

很高興看到你解決了你的問題!不要忘了點擊左邊的複選標記來標記答案。 – 2011-03-25 01:21:49

0

使用佈局權重,並將固定值設置爲0,另一個設置爲任意數量。

+0

沒有工作。請看我更新的評論。 – automaton 2011-03-24 20:28:04

1

是的,其實很簡單。

第一個單元的權重必須爲0.第二個單元的權重必須爲1,並按寬度填充父級。這樣它將佔用它所在容器內的重新裝修空間。

簡單!以下是爲您提供方便

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="0" android:background="#FF0000"> 
    <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="SomeText" android:id="@+id/theview"/> 
    </LinearLayout> 
    <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#FFFF00"> 

    </LinearLayout> 

</LinearLayout> 

爲例===================================== ==

UPDATE

讓你像Crayze那樣過度複雜!

首先。你不需要表格佈局。

第二個問題是您將佈局的兩個高度都設置爲fill_parrent。所以他們都在爭奪屏幕尺寸。要解決這個問題,你只需要將兩個佈局大小都設置爲wrap_content。這將工作得很好。這裏有一個例子,沒有你的代碼表。

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:layout_weight="1" android:background="#FF0000"> 

    <ListView android:id="@+id/edit_group_listView" 
     android:layout_width="fill_parent" android:layout_height="fill_parent" /> 

</LinearLayout> 

<LinearLayout android:orientation="horizontal" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:layout_weight="0" android:background="#FFFF00"> 


      <Button android:text="@string/button_save" android:id="@+id/edit_group_save" 
       android:layout_width="150dip" android:layout_height="50dip" 
       android:enabled="false" android:layout_column="1"></Button> 

      <Button android:text="@string/button_cancel" android:id="@+id/edit_group_cancel" 
       android:layout_width="150dip" android:layout_height="50dip" 
       android:layout_column="3"></Button> 


</LinearLayout> 
+0

我更新了我的評論,因爲這對我無效 – automaton 2011-03-24 20:26:04

+0

更新瞭解決方案。看看 – Taranasus 2011-03-25 14:12:33