2010-11-10 18 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" ... />

组合为我工作。