2011-01-23 129 views
1

我對android相當陌生,並且在佈局上遇到一些問題。下面是我想讓佈局看起來像的一個近似值。 (我希望列表首先在屏幕下方顯示,以便用戶可以向下滾動以查看它。)但是,我現在的代碼使得左側的所有視圖只佔用屏幕的四分之一而不是一半,如圖所示,即使我已將所有寬度設置爲fill_parent。Android中的佈局問題

此外,此佈局似乎弄亂了我的自定義視圖上的座標系統。通常情況下,這不是什麼大問題,但在這種情況下,我正在使用該視圖來繪製圖片,並且圖片最終出現在錯誤的地方。有誰知道如何解決這些問題? alt text

這裏是我的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:orientation="vertical"> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:orientation="vertical"> 
<TableRow> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="fill_parent" android:orientation="vertical" 
android:layout_width="fill_parent"> 
<TableRow> 
<TextView android:text="Resultant Force" android:id="@+id/resForceTitle" 
    android:textSize="25dip" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:padding="3dip" 
    android:gravity="center" android:layout_span="2" /> 
</TableRow> 
<TableRow> 
<TextView android:id="@+id/magText" android:text="Magnitude (N) =" 
    android:textSize="15dip" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:padding="3dip" 
    android:gravity="center_vertical" android:layout_span="2" /> 
</TableRow> 
<TableRow> 
<EditText android:id="@+id/magnitude" android:inputType="numberDecimal" 
    android:layout_width="fill_parent" android:padding="3dip" 
    android:layout_height="fill_parent" android:layout_span="2" /> 
</TableRow> 
<TableRow> 
<TextView android:id="@+id/dirText" android:text="Angle (deg) =" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:textSize="15dip" android:gravity="center_vertical" 
    android:layout_span="2" /> 
</TableRow> 
<TableRow> 
<EditText android:id="@+id/direction" android:inputType="numberDecimal" 
    android:layout_height="fill_parent" android:padding="3dip" 
    android:layout_width="fill_parent" android:layout_span="2" /> 
</TableRow> 
<TableRow> 
<Button android:id="@+id/pushButton" android:text="Add Force" 
    android:layout_height="fill_parent" android:padding="3dip" 
    android:layout_width="fill_parent" /> 
<Button android:id="@+id/clearButton" android:text="Clear" 
    android:layout_height="fill_parent" android:padding="3dip" 
    android:layout_width="fill_parent" /> 
</TableRow> 
</TableLayout> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent"> 
<android.physicsengine.AxisDrawing 
android:id="@+id/image" android:layout_width="fill_parent" 
android:layout_height="fill_parent" /> 
</FrameLayout> 
</TableRow> 
</TableLayout> 
<ListView android:id="@android:id/list" android:layout_height="wrap_content" 
android:padding="3dip" android:layout_width="fill_parent" 
android:clickable="false" /> 
<TextView android:id="@android:id/empty" android:text="Add Forces to List Components" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:textSize="15dip" android:gravity="center_vertical" /> 
</LinearLayout> 

回答

4

從你的XML的外觀看起來你誤會什麼FILL_PARENT手段。它意味着「和我的父母一樣大。」另外,爲什麼你使用兩個嵌套的TableLayouts?爲了把屏幕均勻兩個你應該使用水平的LinearLayout,並給每個孩子(的TableLayout和您的自定義視圖)0dip的寬度和1 layout_weight:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <TableLayout 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_height="wrap_content"> 
      ... 
    </TableLayout> 
    <android.physicsengine.AxisDrawing 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_height="wrap_content" /> 
</LinearLayout> 
+0

我還沒有遇到過,一個LinearLayout與權重不是比TableLayouts更好的選擇。 – schwiz 2011-01-23 02:50:17

0

那是因爲你已經輸入的android:您的EditText中的layout_span =「2」。如果你更正常地刪除這些行爲。

然後,您可以通過將EditText的寬度設置爲200dp來控制左側,例如... 您還可以使用EditText的右側邊距來控制左側列。

至於自定義視圖畫布中的座標,它們從右上角的0,0開始。