2011-11-12 40 views
3

我正試圖讓地圖只填充屏幕的上半部分和下半部分的其他一些佈局。現在我知道這應該可以使用權重結合tablelayout。但是同一段XML代碼與所說的按鈕完美匹配,但與地圖無關。
Screenshots here將MapView限制爲屏幕的一半

的XML代碼:

<TableLayout 
    android:id="@+id/tableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     > 
      <com.google.android.maps.MapView 
      android:id="@+id/map2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:apiKey="0_z4IHjB6EnXohnoyoudontgoVmhg" 
      android:clickable="true" > 
     </com.google.android.maps.MapView> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
     <Button android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="SECOND"></Button> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
     <Button android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="SECOND"></Button> 
    </TableRow> 
</TableLayout> 

如果更換的MapView塊的說一個按鈕,它看起來就像在截圖的第一形象,而現在它看起來像第二一。
在這兩種情況下,我沒有更改任何重量參數或layout_width或height,但它以某種方式更改大小。任何想法如何讓MapView只覆蓋一半的屏幕?

+0

我認爲唯一的方法是以編程方式進行。 –

+0

以及這將如何完成? – Urban

+1

您不要在'TableLayout'和'TableRow'中使用'layout_width'和'layout_height'。切換到嵌套'LinearLayouts',或者使用'RelativeLayout',或者其他東西。 – CommonsWare

回答

5

對不起城市,給你指點錯就可以了 - 我看着這之前,我可能會限制地圖大小的唯一途徑是編程,但是,因爲我已經有這種佈局的完成它:

<?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" >   

<FrameLayout android:id="@+id/map_frame" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.7" >  

    <com.google.android.maps.MapView 
     android:id="@+id/map_view" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:enabled="true" 
     android:clickable="true"    
     android:apiKey="dgvbdj_my_secret_key_nvc8mxcksos"/> 

</FrameLayout> 

<co.uk.mycompany.ui.MapNavBar 
    android:id="@+id/map_nav" 
    android:layout_width="fill_parent" 
    android:layout_height="70dip" 
    android:layout_gravity="bottom" 
    android:layout_weight="0.3" /> 

顯示的最後一個項目是一個自定義窗口小部件,但佈局應顯示所涉及的原理。這限制了地圖的高度,但允許它變寬。

+0

Thx @John。我用一個Linearlayout來代替它,但它基本上是一樣的東西......不知道是什麼讓我在第一個地方使用表格。 – Urban