【问题标题】:adding buttons above map在地图上方添加按钮
【发布时间】:2014-03-26 16:07:22
【问题描述】:

我正在处理一个包含地图的活动,并尝试在其上添加按钮,这就是我的 xml 的样子

这是我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/multi_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal" >

<FrameLayout
    android:id="@+id/container_a"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" >
</FrameLayout>


<RelativeLayout
    android:layout_width="0dp"
     android:id="@+id/container_b"
    android:layout_height="match_parent"
    android:layout_weight="1" >

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

    <RadioGroup
        android:id="@+id/radio_group_list_selector"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:background="#80000000"
        android:orientation="horizontal"
        android:padding="4dp" >

        <Button
            android:id="@+id/driving"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/bkg"
            android:drawableTop="@drawable/car"
            android:gravity="center_horizontal|center_vertical" />

        <Button
            android:id="@+id/radioAZ"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/bkg"
            android:drawableTop="@drawable/walk"
            android:gravity="center_horizontal|center_vertical" />

        <Button
            android:id="@+id/bicycling"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/bkg"
            android:drawableTop="@drawable/bicycle"
            android:gravity="center_horizontal|center_vertical" />
    </RadioGroup>
</RelativeLayout>

但是,当我运行该应用程序时,该地图仍然位于按钮顶部,有人知道我如何将按钮放在地图顶部以便用户可以看到和使用它们吗?沿着 z-index 线左右的东西?

【问题讨论】:

    标签: android xml google-maps button


    【解决方案1】:

    您正在 XML 上放置一个 SupportMapFragment,并将包含该片段和按钮的 FrameLayout 替换为另一个片段。

    【讨论】:

    • 所以我需要在添加地图后逐步添加按钮?
    • 我不明白您为什么要在代码中再次添加地图。您已经在 XML 文件中拥有它。如果你想得到它并在代码中使用它,你应该使用getSupportFragmentManager().findFragmentById(R.id.fragment2);
    • 是的,我看到它是以前版本留下的错误,对此我很抱歉,但我似乎仍然看不到按钮,地图正在覆盖它们,知道吗?
    • 按钮应该是可见的,因为它们是 RelativeLayout 上的最后一项并且具有最高的 z-index。我在我的一个应用程序中有一个类似的布局,我的做法几乎和你一样——我只是不使用 RadioGroup 项目。我真的不知道他们为什么不显示......
    • 那是我开始的地方,但是,地图仍然覆盖按钮,当地图发生变化时,我会看到它们几分之一秒
    猜你喜欢
    • 1970-01-01
    • 2016-11-19
    • 1970-01-01
    • 2018-05-15
    • 1970-01-01
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    相关资源
    最近更新 更多