【问题标题】:How do I create a box to hold text below Google maps within android?如何在 android 中创建一个框来保存 Google 地图下方的文本?
【发布时间】:2014-02-19 02:09:39
【问题描述】:

此时我知道如何在 Android 中使用 Google 地图,但它似乎总是占据整个窗口,下面有一张图片显示了我正在尝试完成的工作(在 Google 地图下方有一个框,我可以存储文本即“Hello World”

如何在 Google 地图下方添加框,以便存储文本,即“Hello World”

到目前为止的代码:

ActivityMain:

公共类 MainActivity 扩展 Activity {

    private GoogleMap googleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try {
            initilizeMap();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    private void initilizeMap() {
        if (googleMap == null) {
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        initilizeMap();
    }

}

Android xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

图片:(图片链接) http://s28.postimg.org/j6xes5659/Google_Maps_Help.png

【问题讨论】:

    标签: java android xml eclipse google-maps


    【解决方案1】:

    &lt;fragment&gt; 中的android:layout_height 属性设置为match_parent,这意味着它将占用其父级中的所有可用垂直空间。有几种方法可以实现您想要的。例如,您可以将&lt;fragment&gt; 和所需的文本包装在垂直的LinearLayout 上,并为片段设置一些定义的高度(即android:layout_height="200dp"

    【讨论】:

    • 您能否进一步解释您的解决方案?我可以理解我需要更改布局高度,但在那之后,我仍然不知所措。
    • 试试吧。在 xml 中的片段下方添加类似Button 的内容(使用android:layout_below="@id/map" 将其放在片段下方)。一开始它不会显示,但是当您调整高度时它会显示。
    猜你喜欢
    • 2023-04-06
    • 2019-09-18
    • 2021-02-20
    • 1970-01-01
    • 2019-01-04
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    相关资源
    最近更新 更多