Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在谷歌地图下创建按钮_Android_Google Maps_Button - Fatal编程技术网

Android 在谷歌地图下创建按钮

Android 在谷歌地图下创建按钮,android,google-maps,button,Android,Google Maps,Button,我想在谷歌地图下面添加两个对齐的按钮。我曾尝试在下面添加按钮,但它并没有显示出来。每当我尝试更改地图的大小时,不同设备的界面会有所不同。我怎么做?请帮忙。下面是我的代码,没有按钮代码- 活动_maps.xml- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match

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

活动_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>

您可以通过为包含editText和按钮的地图片段和线性布局指定
layout\u weight
属性来实现

例如:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_weight="1"
    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"
    android:layout_weight="1"
    tools:context=".MapsActivity"
    android:name="com.google.android.gms.maps.SupportMapFragment" />


这将平均分割地图片段和线性布局的空间,但是可以尝试不同的数字来实现您想要的

如果我猜对了,您的问题是地图片段下方的任何按钮(在主
线性布局
内)都不可见。这可以通过将地图片段的
layout\u height
设置为
0dp
并将其
layout\u weight
设置为
1
来解决。地图片段上方和下方的UI元素应将
layout\u height
设置为
wrap\u content
,就像您所做的那样

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

作为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>

不,先生,它不工作。我的意思是我没有得到我想要的。我希望您已经看到uber应用程序主屏幕。它有一个应用程序,搜索栏和下面的一些按钮。我想做那样的事。你能帮帮我吗?