How can I add a TextView below a MapView?

匆匆过客 提交于 2019-12-24 01:22:12

问题


I followed Hello Views, Google Map View and now I want to add a TextView under below the MapView. I have only changed the layout file main.xml and placed the MapView and the TextView in a vertical LinearLayout. My Eclipse is set to build this automatically, but when I run the application in the emulator, I can only see the MapView.

How can I add a TextView below a MapView?

Here is my layout 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>

回答1:


The issue you have is that you are using android:layout_height="fill_parent" in your MapView.

I don't get if you want:

  • The TextView to be over the map
  • Shrink the MapView to leave space for the TextView

In the first case use a <RelativeLayout> instead of a <LinearLayout> and play with the android:layout_alignParentBottom="true" for the TextView.

In the second case, use android:layout_weight. I don't have eclipse opened but placing android:layout_weight="1"to the TextView should be enough.




回答2:


You might like to try a RelativeLayout like:

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

I couldn't get MapViews to work very well with LinearLayouts




回答3:


Only the combination of

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

and

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

worked for me.



来源:https://stackoverflow.com/questions/4143858/how-can-i-add-a-textview-below-a-mapview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!