簡體   English   中英

如何在MapView下面添加TextView?

[英]How can I add a TextView below a MapView?

我關注了Hello Views,Google Map View ,現在我想在MapView下面添加一個TextView 我只更改了布局文件main.xml ,並將MapViewTextView放在垂直的LinearLayout 我的Eclipse設置為自動構建,但是當我在模擬器中運行應用程序時,我只能看到MapView

如何在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>

你可能想嘗試一下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一起使用

你遇到的問題是你在MapView中使用android:layout_height="fill_parent"

如果你願意,我不會得到:

  • TextView要在地圖上
  • 縮小MapView以留出TextView空間

在第一種情況下,使用<RelativeLayout>而不是<LinearLayout>並使用android:layout_alignParentBottom="true"作為TextView

在第二種情況下,使用android:layout_weight 我沒有打開eclipse但將android:layout_weight="1"放到TextView應該就夠了。

只有組合

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

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

為我工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM