Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show MapView inside of CardView?

I need to use MapView inside of CardView by getting current location.

Your answer is more appreciated. Thanks in advance...

enter image description here

like image 530
Parama Sudha Avatar asked Oct 26 '25 09:10

Parama Sudha


2 Answers

I think this will work:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">


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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Sum text if you need" />

        <com.google.android.gms.maps.MapView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

</android.support.v7.widget.CardView>

CardView itself is no more than an ordinary FrameLayout with few aesthetic additions. Hence you could inflate anything you want inside of it.

From the docs of CardView:

A FrameLayout with a rounded corner background and shadow.

This is just from a layout perspective, to get MapView to actually work you'll need a couple of additional setup. Here's a couple of resources in which you could learn a bit more about it:

  • Official guide from Google Developers.
  • Tutorial on MapView v2 by Vogella.
like image 108
Hadi Satrio Avatar answered Oct 28 '25 22:10

Hadi Satrio


<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardCornerRadius="2dp"
    app:cardElevation="4dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/title"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:text="Will Be Delievered To" />

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

        <TextView
            android:id="@+id/subtext"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:text="Blah Blah Blah" />

    </LinearLayout>

</android.support.v7.widget.CardView>

Use Fragment over MapView. When you use the Fragment, use either name MapFragment or SupportMapFragment.

like image 26
Martin Sing Avatar answered Oct 28 '25 23:10

Martin Sing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!