2014-03-27 83 views
-1

我想要做的是在MapFragment v2的左下角添加Button。MapFragment右下角的按鈕

問題是我的MapFragment在LinearLayout裏面,因爲它下面也有AdView,所以我不能使用父對象。

我的代碼:

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

當我使用它就像我的MapFragment不會出現在所有。

下圖所示。

_____________________ 
|     | 
|     | 
|     | 
|     | 
|  MapFragment | 
|     | 
|     | 
|     | 
|     | 
| {Button}   | 
|____________________| 
|     | 
|  AdView  | 
|____________________| 

回答

2

重量只有線性佈局工作,因此提供了一個高度,在地圖上的片段刪除重

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

哦,那是太明顯了>。< 由於現在隊友般的魅力的作品設置爲

android:layout_alignParentBottom="true" 

和MapFragment! – JakubW

+0

不客氣。 –

0

試試這個..

更改fragmentmatch_parent和刪除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> 
1

你可以只是把一切RelativeLayout的內,AdView的與

android:layout_above="@+id/adView" 
相關問題