如何在 MapView 下方添加 TextView?

发布于 2024-10-01 23:05:39 字数 1196 浏览 2 评论 0原文

我关注了 Hello Views,Google 地图视图,现在我想要在 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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

牛↙奶布丁 2024-10-08 23:05:39

您遇到的问题是您在 MapView 中使用 android:layout_height="fill_parent"

如果您想要的话,我不明白:

  • TextView 位于地图上方
  • 缩小 MapViewTextView 留出空间

在第一种情况下使用 而不是 并使用 android:layout_alignParentBottom="true" 作为 文本视图

在第二种情况下,使用android:layout_weight。我没有打开 Eclipse,但将 android:layout_weight="1" 放置到 TextView 应该就足够了。

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.

倾听心声的旋律 2024-10-08 23:05:39

您可能想尝试像这样的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很好地配合

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

泪是无色的血 2024-10-08 23:05:39

的组合

为我工作。

Only the combination of

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

and

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

worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文