anuradha
anuradha

Reputation: 692

show textview on google map in android

I am trying to place a TextView on GoogleMap in my android application. Please see the following code that I wrote so far. When I run it the TextView does not appear on the GoogleMap.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".activity.HomeActivity"
    tools:showIn="@layout/app_bar_main">

    <LinearLayout
        android:id="@+id/validity"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="vertical"
        android:layout_alignParentBottom="true">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="You are not a paid user."/>
    </LinearLayout>

    <fragment
        android:id="@+id/home_map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="false"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

Please suggest me possible solution to solve this issue.

Upvotes: 2

Views: 3680

Answers (3)

Hema Devi Vanapalli
Hema Devi Vanapalli

Reputation: 163

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#EEE">


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/linear"
        android:layout_marginTop="10dp"
        android:gravity="center">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="40dp"
                    android:layout_marginRight="40dp"
                    android:background="#ffffff">
                    <Spinner
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/spinner"
                        android:fontFamily="@string/fontmedium"
                        android:textColor="@color/normalfont"
                        android:textSize="16sp"
                        android:layout_marginLeft="10dp"
                        android:layout_marginRight="10dp"
                        >

                    </Spinner>
                </LinearLayout>

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="40dp"
                    android:layout_marginRight="40dp"
                    android:background="@drawable/borderss"
                    android:layout_marginTop="20dp"
                    android:padding="15dp"
                    android:gravity="center"
                    android:id="@+id/res_acc"
                    android:textAlignment="center"
                    android:imeOptions="actionDone"
                    android:fontFamily="@string/fontmedium"
                    android:textColor="@color/normalfont"
                    android:textSize="16sp"
                    android:hint="Enter City name"
                    />


                <android.support.v7.widget.AppCompatButton
                    android:id="@+id/details"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:textColor="#ffffff"
                    android:layout_marginRight="16dp"
                    android:layout_marginLeft="15dp"
                    android:fontFamily="@string/fontmedium"

                    android:textSize="14sp"
                    android:padding="10dp"
                    android:text=" View Map "
                    android:background="@drawable/receiptt"
                    android:layout_gravity="center"
                    android:layout_marginTop="20dp" />
            </LinearLayout>
        </ScrollView>

        <fragment 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:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.example.map_sample" />

    </LinearLayout>


</android.support.design.widget.CoordinatorLayout>

Upvotes: 1

Vivek Mishra
Vivek Mishra

Reputation: 5705

Use FrameLayout instead of Relative Layout like this. I have tested this and this is working

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <fragment
        android:id="@+id/home_map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="false"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true" />
    <LinearLayout
        android:id="@+id/validity"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="vertical"
        android:layout_gravity="bottom"
        android:background="@android:color/white">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="You are not a paid user."
            />
    </LinearLayout>



</FrameLayout>

Upvotes: 7

Rahul
Rahul

Reputation: 1422

Use This code

<fragment
    android:id="@+id/home_map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="false"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true" />
<LinearLayout
    android:id="@+id/validity"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="vertical"
    android:layout_alignParentBottom="true">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="You are not a paid user."/>
</LinearLayout>

Upvotes: 2

Related Questions