Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.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
Java 将多个按钮添加到框架布局(android)_Java_Android_Android Framelayout - Fatal编程技术网

Java 将多个按钮添加到框架布局(android)

Java 将多个按钮添加到框架布局(android),java,android,android-framelayout,Java,Android,Android Framelayout,我有一个在框架布局中使用谷歌地图的应用程序。我在(接受的)答案中使用了备选方案2。当我使用备选方案2时,我在应用程序顶部有一个按钮(自由绘制)。我的问题是,我可以在这个按钮的两侧添加多个按钮(水平/垂直)吗 我在网上搜索过类似的问题,但大多数情况下,答案涉及两种不同的布局。我是android的初学者,不知道如何使用两种不同的布局。我尝试使用两种布局,但出现了一个错误“多个根标记”。有什么方法可以解决这个问题吗 任何帮助都将不胜感激。在您的root_map.xml中类似的内容将在地图的左上角为您提

我有一个在框架布局中使用谷歌地图的应用程序。我在(接受的)答案中使用了备选方案2。当我使用备选方案2时,我在应用程序顶部有一个按钮(自由绘制)。我的问题是,我可以在这个按钮的两侧添加多个按钮(水平/垂直)吗

我在网上搜索过类似的问题,但大多数情况下,答案涉及两种不同的布局。我是android的初学者,不知道如何使用两种不同的布局。我尝试使用两种布局,但出现了一个错误“多个根标记”。有什么方法可以解决这个问题吗


任何帮助都将不胜感激。

在您的root_map.xml中类似的内容将在地图的左上角为您提供两个相邻的按钮:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:layout_width="fill_parent"
        android:layout_height="fill_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

    <LinearLayout
        android:id="@+id/fram_map"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btn_draw_State"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Free Draw" />

        <Button
            android:id="@+id/btn_dosomethingelse"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Do Something Else" />

    </LinearLayout>

</FrameLayout>

当然可以。您可以添加任意数量的按钮。要控制它们在FrameLayout中的位置,必须使用
android:layout\u gravity
属性将重力指定给每个子级

例如:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom">

        <Button
            android:id="@+id/buttonA"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button A"/>
        <Button
            android:id="@+id/buttonB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button B"/>
    </LinearLayout>
</FrameLayout>

关于您的错误“多个根标记”: