2010-11-10 93 views
2

我跟着Hello Views, Google Map View,現在我想在MapView的下面添加一個TextView。我只更改了佈局文件main.xml,並將MapViewTextView放置在垂直LinearLayout中。我的Eclipse被設置爲自動生成,但是當我在模擬器中運行應用程序時,我只能看到MapView如何在MapView下添加TextView?

如何在MapView下面添加TextView

這裏是我的佈局main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    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="fill_parent" 
     android:layout_height="fill_parent" 
     android:clickable="true" 
     android:apiKey="my key" 
    /> 

    <TextView 
     android:id="@+id/textview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="My TextView" 
    /> 

</LinearLayout> 

回答

5

的問題是您在MapView中使用android:layout_height="fill_parent"

,如果你想我不明白:

  • TextView是地圖
  • 在收縮的MapViewTextView

留出空間,在第一種情況下使用<RelativeLayout>而不是<LinearLayout>,與android:layout_alignParentBottom="true"一起玩。

在第二種情況下,使用android:layout_weight。我沒有打開日食,但將android:layout_weight="1"設置爲TextView應該足夠了。

+1

謝謝,我在'MapView'(1.0)和'TextView'(0.0)上增加了一個權重,現在它工作。 – Jonas 2010-11-10 12:09:56

5

你可能想嘗試像的RelativeLayout:

<?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"> 
    <TextView 
     android:id="@+id/MyTextView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" 
     android:layout_alignParentBottom="true" /> 
    <com.google.android.maps.MapView 
     android:id="@+id/map" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:apiKey="Your api key" 
     android:enabled="true" 
     android:clickable="true" 
     android:layout_above="@+id/MyTextView"" /> 
</RelativeLayout> 

我不能讓MapViews工作非常好,LinearLayouts

2

只有

<TextView android:layout_alignParentBottom="true" ... />

<com.google.android.maps.MapView android:layout_above="@+id/MyTextView" ... />

組合爲我工作。