Android 按钮不显示

Android 按钮不显示,android,button,android-linearlayout,android-framelayout,Android,Button,Android Linearlayout,Android Framelayout,我在activity_maps.xml中有以下代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_height="wrap_content" android:lay

我在activity_maps.xml中有以下代码:

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

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

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

    <Button
        android:id="@+id/btnRestaurant"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nearby Restaurants"
        android:visibility="visible" />

    <Button
        android:id="@+id/btnHospital"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nearby Hospitals"
        android:visibility="visible" />

    <Button
        android:id="@+id/btnSchool"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nearby Schools"
        android:visibility="visible" />
</FrameLayout>


我面临的问题是,每当我打开应用程序,它都不会显示任何按钮,只有地图和当前位置。请帮助,谢谢。

请将片段放入框架布局中

像这样:

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

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

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

    <Button
        android:id="@+id/btnRestaurant"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nearby Restaurants"
        android:visibility="visible" />

    <Button
        android:id="@+id/btnHospital"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nearby Hospitals"
        android:visibility="visible" />

    <Button
        android:id="@+id/btnSchool"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nearby Schools"
        android:visibility="visible"/>
  </LinearLayout>
</FrameLayout>


希望这对您有所帮助,谢谢:)

您的地图碎片高度以“匹配父对象”的形式给出,这就是为什么它占据了布局上的所有屏幕。将其作为包装内容保存,并使用相对布局确保按钮出现在屏幕底部。这里,地图片段中的“alignParentTop”确保地图位于屏幕顶部,上面的布局确保地图不会占据所有屏幕,按钮布局中的“alignParentBottom”确保按钮位于底部。尽量不要为布局指定任何静态高度。这会妨碍应用程序的响应

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:orientation="vertical">

    <fragment
        android:layout_alignParentTop="true"
        android:id="@+id/map"
        android:layout_above="@+id/layout_buttons"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_contant"></fragment>

    <FrameLayout
        android:id="@+id/layout_buttons"
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/btnRestaurant"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nearby Restaurants"
            android:visibility="visible" />

        <Button
            android:id="@+id/btnHospital"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nearby Hospitals"
            android:visibility="visible" />

        <Button
            android:id="@+id/btnSchool"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nearby Schools"
            android:visibility="visible" />
    </FrameLayout>

    </RelativeLayout>


为什么要将按钮放在FrameLayout中?您的布局乱七八糟。这是一个很好的起点。有一个错误提示错误:错误:未找到属性'android:alignParentBottom',错误:未找到属性'android:alignParentTop',错误:未找到属性'android:alignParentTop',错误:未找到属性'android:alignParentBottom',抱歉,我的属性名称错误,将被删除“android:layout\u alignParentTop”和“android:layout\u alignParentBottom”“按钮正在显示,应用程序只是空白,只有按钮,如果我按下按钮,它只会显示toast messageDude,只要给我你想要的布局设计,嘿,用framelayout创建一个布局,并复制片段和线性布局。请在线性布局中添加方向