what I want to do is add Button in the bottom|left corner of MapFragment v2.
The problem is that my MapFragment is inside LinearLayout because there is also AdView below it so I cannot work with PARENT aligns.
My code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.powa.Activites.MapActivity"
tools:ignore="MergeRootFrame">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
>
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="@+id/mailBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/map"
android:layout_alignLeft="@+id/map"
android:text="MAIL" />
</RelativeLayout>
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/map"
android:background="@color/black"
ads:adSize="SMART_BANNER"
ads:adUnitId="XOXOXOXO" />
When i use it like that my MapFragment does not appear at all.
Desired look below.
_____________________
| |
| |
| |
| |
| MapFragment |
| |
| |
| |
| |
| {Button} |
|____________________|
| |
| AdView |
|____________________|
Weights work only in Linear-layout , so provide a height and remove weight on map fragment
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/mailBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/map"
android:layout_alignLeft="@+id/map"
android:text="MAIL" />
</RelativeLayout>
You could just put everything inside a RelativeLayout , set the AdView to
android:layout_alignParentBottom="true"
and the MapFragment with
android:layout_above="@+id/adView"
Try this..
Change your fragment
as match_parent
and remove android:layout_weight="1"
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:id="@+id/mailBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/map"
android:layout_alignLeft="@+id/map"
android:text="MAIL" />
</RelativeLayout>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.