-2

I have this code in 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>

The problem that I am facing is that whenever I open the app it is showing none of the buttons, only the map and the current location. Please Help, Thank You.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
TEP neil
  • 11
  • 2

2 Answers2

1

Your map fragment height is given as "match_parent", that's why it takes all the screen on your layout. keep it as wrap_content and use relative layout to make sure that the buttons are present on the screen at the bottom. here "alignParentTop" in the map fragment makes sure the map is on top of the screen and layout_above makes sure your map does not take all the screen, "alignParentBottom" in the button layout makes sure the buttons are on the bottom. try not to assign any static height to your layout. it will hamper the responsiveness of your app.

<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>
Sabid Habib
  • 419
  • 1
  • 4
  • 16
  • there is an error saying Error:error: attribute 'android:alignParentBottom' not found, Error:error: attribute 'android:alignParentTop' not found, Error:attribute 'android:alignParentTop' not found, Error:attribute 'android:alignParentBottom' not found – TEP neil Mar 24 '18 at 21:50
  • sorry, wrong attribute name by me, it will be "android:layout_alignParentTop" and "android:layout_alignParentBottom" – Sabid Habib Mar 25 '18 at 07:06
  • the buttons are showing up and the app is just blank with buttons only, if I press the buttons it just shows the toast message – TEP neil Mar 25 '18 at 13:09
0

please put fragment inside the framelayout

like this:

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

hope this will help you ,Thanks :)

Nidheesh
  • 109
  • 9