2011-09-15 72 views
0

我明顯錯過了一些最後一點的信息 - 在主要RelativeLayout,第二/最後一項,LinearLayout與2圖像被ViewFlipper「推下」屏幕。如果我爲ViewFlipper內部的第二個佈局(LinearLayout/MapView)指定硬編碼高度,那麼消失的LinearLayout將顯示出來,但當然不是這樣做的。感謝這裏的任何提示。Android佈局問題

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:a="http://schemas.android.com/apk/res/android" 
    a:layout_width="fill_parent" 
    a:layout_height="fill_parent" 
    a:background="#ffffff" 
    a:id="@+id/layout_main"> 

    <ViewFlipper 
     a:layout_width="fill_parent" 
     a:layout_height="wrap_content" 
     a:id="@+id/MainFlipper"> 

     <ScrollView 
      a:id="@+id/ScrollView1" 
      a:layout_width="fill_parent" 
      a:layout_height="wrap_content"> 

      <LinearLayout 
       a:orientation="vertical" 
       a:layout_width="fill_parent" 
       a:background="#ffffff" 
       a:layout_height="wrap_content"> 

       <TableLayout a:layout_width="wrap_content" a:id="@+id/tableLayout1" 
        a:layout_height="wrap_content"> 
        <TableRow a:layout_height="wrap_content" a:layout_width="wrap_content"> 
         <TextView a:layout_column="1" a:text="S" /> 
         <Spinner a:id="@+id/SSpinner" a:layout_width="wrap_content" 
          a:layout_height="wrap_content" /> 
        </TableRow> 
        <TableRow a:layout_width="wrap_content" a:layout_height="wrap_content"> 
         <TextView a:layout_column="1" a:text="C" /> 
         <Spinner a:id="@+id/CSpinner" a:layout_width="wrap_content" 
          a:layout_height="wrap_content" /> 
        </TableRow> 
        <TableRow a:layout_width="wrap_content" a:layout_height="wrap_content"> 
         <TextView a:layout_column="1" a:text="J" /> 
         <Spinner a:id="@+id/JSpinner" a:layout_width="wrap_content" 
          a:layout_height="wrap_content" /> 
        </TableRow> 
        <TableRow a:layout_width="wrap_content" a:layout_height="wrap_content"> 
         <TextView a:layout_column="1" a:text="L" /> 
         <Spinner a:id="@+id/LSpinner" a:layout_width="wrap_content" 
          a:layout_height="wrap_content" /> 
        </TableRow> 
       </TableLayout> 
       <TextView a:text=" " a:layout_width="wrap_content" 
        a:layout_height="wrap_content" /> 
       <TextView a:text="Fill in only one field, then click Calculate" 
        a:layout_width="wrap_content" a:layout_height="wrap_content" /> 
       <TableLayout a:layout_width="wrap_content" 
        a:layout_height="wrap_content"> 
        <TableRow a:layout_height="wrap_content" a:layout_width="wrap_content"> 
         <TextView a:layout_column="1" a:text="Price1 ($)" /> 
         <EditText a:layout_width="200px" a:inputType="numberDecimal" 
          a:id="@+id/P1EditText" a:layout_height="wrap_content" 
          a:cursorVisible="false" /> 
        </TableRow> 
        <TableRow a:layout_width="wrap_content" a:layout_height="wrap_content"> 
         <TextView a:layout_column="1" a:text="Page" /> 
         <EditText a:layout_width="wrap_content" a:inputType="number" 
          a:id="@+id/PageNoEditText" a:layout_height="wrap_content" /> 
        </TableRow> 
        <TableRow a:layout_width="wrap_content" a:layout_height="wrap_content"> 
         <TextView a:layout_column="1" a:text="Price2 ($)" /> 
         <EditText a:layout_width="wrap_content" a:inputType="numberDecimal" 
          a:id="@+id/P2EditText" a:layout_height="wrap_content" /> 
        </TableRow> 
       </TableLayout> 
       <TextView a:id="@+id/E1TextView" a:text=" " 
        a:layout_width="wrap_content" a:layout_height="wrap_content" /> 
       <TableLayout a:layout_width="wrap_content" 
        a:layout_height="wrap_content"> 
        <TableRow a:layout_height="wrap_content" a:layout_width="wrap_content"> 
         <Button a:onClick="ClickCalculateButton" a:text="Calculate" 
          a:id="@+id/CalculateButton" a:layout_height="wrap_content" 
          a:layout_width="wrap_content" /> 
         <Button a:onClick="ClickClearButton" a:text="Clear Fields" 
          a:id="@+id/ClearButton" a:layout_width="wrap_content" 
          a:layout_height="wrap_content" /> 
        </TableRow> 
       </TableLayout> 
      </LinearLayout> 
     </ScrollView> 

     <LinearLayout 
      a:id="@+id/ScrollView2" 
      a:layout_width="fill_parent" 
      a:layout_height="wrap_content"> 
      <com.google.android.maps.MapView 
       a:id="@+id/mapView" 
       a:enabled="true" 
       a:clickable="true" 
       a:layout_width="fill_parent" 
       a:layout_height="wrap_content" 
       a:apiKey="my-key" /> 
     </LinearLayout> 
    </ViewFlipper> 

    <LinearLayout 
     a:layout_below="@+id/MainFlipper" 
     a:layout_width="fill_parent" 
     a:id="@+id/linearLayout1" 
     a:layout_alignParentBottom="true" 
     a:gravity="bottom|center" 
     a:layout_height="fill_parent"> 

     <ImageView 
      a:layout_height="wrap_content" 
      a:layout_width="wrap_content" 
      a:id="@+id/imageView1" 
      a:src="@drawable/btn_toggle_on" /> 
     <ImageView 
      a:layout_height="wrap_content" 
      a:layout_width="wrap_content" 
      a:id="@+id/imageView2" 
      a:src="@drawable/btn_toggle_off" /> 
    </LinearLayout> 
</RelativeLayout> 
+0

難道你的地圖視圖佔據了所有可用的高度嗎? –

回答

1

添加a:layout_above="@+id/linearLayout1"到您的腳蹼,並從去年線性佈局中刪除a:layout_below="@+id/MainFlipper"。此外,使用LinearLayout而不是RelativeLayout可能更容易實現。

+0

這太瘋狂了。爲什麼會工作而不是其他? (這是一個bug嗎?) – Conrad

+1

不,這不是bug,它是邏輯上的。你的方法並不限制上面的佈局(鰭狀肢),因爲他甚至不知道第二個佈局,並且佔據了他所能做的所有空間。 – ernazm

+0

@emazm - 謝謝,這很有道理。 – Conrad