在Google地图下创建按钮 [英] Create buttons below google map

查看:146
本文介绍了在Google地图下创建按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在谷歌地图下方添加两个对齐的按钮。我尝试在下面添加按钮,但没有显示,每当我尝试更改地图大小时,界面对于不同的设备都会有所不同。我该怎么做?请帮忙。这里是我的代码下面没有按钮代码给出 -

activity_maps.xml -

  xmlns:android =http://schemas.android.com/apk/res/android
android:layout_width =match_parent
android:layout_height = match_parent
android:orientation =vertical
>

< LinearLayout
android:layout_width =wrap_content
android:layout_height =wrap_content>

< EditText
android:layout_width =200dp
android:layout_height =wrap_content
android:id =@ + id / etSearch/> ;


解决方案

如果我猜对了你的问题,地图片段(在主要 LinearLayout 内)不可见。这可以通过设置地图片段的 layout_height 0dp 并给它一个 layout_weight 1 。地图片段之上和之下的UI元素应该像您所做的那样将 layout_height 设置为 wrap_content

这个想法是,其他UI元素只使用他们需要的屏幕高度,然后地图片段将使用所有剩余的空间。类似的方法通常可用于各种布局,这些布局具有固定高度/宽度的一些元素以及应该缩放到最佳高度/宽度的一个元素。

As XML:

 < LinearLayout 
xmlns:android =http://schemas.android.com/ apk / res / android
android:layout_width =match_parent
android:layout_height =match_parent
android:orientation =vertical
>

< LinearLayout
android:layout_width =wrap_content
android:layout_height =wrap_content>

< EditText
android:layout_width =200dp
android:layout_height =wrap_content
android:id =@ + id / etSearch/> ;


I want to add two aligned buttons below google map.I have tried adding buttons below but its not showing and whenever i try to change size of map,interface gets different for different devices. how can i do it? Please help. Here is my code given below without button code -

activity_maps.xml -

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <EditText
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:id="@+id/etSearch"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="search"
        android:id="@+id/btnSearch"
        android:layout_gravity="end"
        style="?android:attr/buttonStyleSmall"
        android:onClick="onSearch" />

</LinearLayout>

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/map"
    tools:context=".MapsActivity"
    android:name="com.google.android.gms.maps.SupportMapFragment" />

</LinearLayout>

解决方案

If I guessed right your problem is that any Buttons below the map fragment (inside the main LinearLayout) are not visible. This can be solved by setting the map fragment's layout_height to 0dp and giving it a layout_weight of 1. The UI elements above and below the map fragment should have the layout_height set to wrap_content just like you have done.

The idea is that the other UI elements use just the amount of the screen height that they need and the map fragment will then use all the remaining space. A similar approach can commonly be used in all kinds of layouts that have some elements with fixed height/width and one element that is supposed to scale to an optimal height/width.

As XML:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:id="@+id/etSearch"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="search"
            android:id="@+id/btnSearch"
            android:layout_gravity="end"
            style="?android:attr/buttonStyleSmall"
            android:onClick="onSearch" />

    </LinearLayout>

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/map"
        tools:context=".MapsActivity"
        android:name="com.google.android.gms.maps.SupportMapFragment" />

    <!--The Buttons below the map fragment-->
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Button"
            android:id="@+id/button" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Button"
            android:id="@+id/button2" />
    </LinearLayout>

</LinearLayout>

这篇关于在Google地图下创建按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆