2011-06-27 37 views
2

我嘗試使用RelativeLayout並排放置ListViewMapView。然而我的MapView總是高於ListViewRelativeLayout和並列ListView/MapView

這裏是我的main.xml佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 

<com.google.android.maps.MapView 
      android:id="@+id/mapview" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:clickable="true" 
       android:apiKey="0uZMgFMDqZETDVYg843CSoC8rHyuV01ypwz2C2Q" 
       android:layout_alignParentRight="true" android:layout_alignParentTop="true" /> 

    <ListView android:id="@+id/list" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:smoothScrollbar="true" 
     android:background="#fff" android:cacheColorHint="#fff" 
     android:fastScrollEnabled="false" android:clickable="true" 
     android:layout_alignParentLeft="true" android:layout_alignParentTop="true" 
     android:layout_marginBottom="36dp" /> 
</RelativeLayout> 

回答

0

更好地利用TableLayout指定的android:layout_weight =「1」,在雙方的MapView和ListView

如果使用相對佈局,那麼你必須最大寬度設置爲兩個列表視圖並以編程方式顯示地圖視圖

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 

    android:orientation="vertical" 

    android:layout_width="fill_parent" 

    android:layout_height="fill_parent"> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="wrap_content" 

     android:layout_height="wrap_content" 
     android:smoothScrollbar="true" 

     android:background="#ffffff" 
     android:cacheColorHint="#ffffff" 

     android:fastScrollEnabled="false" 
     android:clickable="true" 


     android:layout_alignParentTop="true" 

     android:layout_marginBottom="36dp" 
     /> 
    <com.google.android.maps.MapView 

     android:id="@+id/mapview" 

     android:layout_width="wrap_content" 

     android:layout_height="fill_parent" 

     android:clickable="true" 

     android:apiKey="0uZMgFMDqZETDVYg843CSoC8rHyuV01ypwz2C2Q" 

     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@id/list" /> 




</RelativeLayout> 
+0

好的,謝謝,如果我嘗試使用重量爲「1」的TableLayout,我的列表和mapview不會填充屏幕的高度: http://img862.imageshack.us/img862/9442/bugzt.png 我現在的代碼:http://pastebin.com/t2ie9rs2 – kudos

-1

嘗試在你的MapViewListView都設置android:layout_weight="1"

0

把你的listview放在mapView上面。在兩個視圖中取出alignParentLeft和alignParentRight屬性。然後,在MapView類,添加:

android:layout_toRightOf="@+id/list" 
+0

不起作用!我的mapview現在是不可見的: http://pastebin.com/3UzqFZsb – kudos