2014-09-13 103 views
0

我有一個像這樣通過AdMob廣告抽屜式導航佈局正確:AdMob廣告顯示在導航抽屜佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:id="@+id/relative_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<!-- As the main content view, the view below consumes the entire 
    space available using match_parent in both dimensions. --> 
<FrameLayout 
    android:id="@+id/content_frame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<!-- android:layout_gravity="start" tells DrawerLayout to treat 
    this as a sliding drawer on the left side for left-to-right 
    languages and on the right side for right-to-left languages. 
    The drawer is given a fixed width in dp and extends the full height of 
    the container. A solid background is used for contrast 
    with the content view. --> 
<ListView 
    android:id="@+id/left_drawer" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:choiceMode="singleChoice" 
    android:divider="@android:color/transparent" 
    android:dividerHeight="0dp" 
    android:background="#111"/> 
</android.support.v4.widget.DrawerLayout> 

<com.google.android.gms.ads.AdView android:id="@+id/adView" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        ads:adSize="BANNER" 
        android:layout_alignParentBottom="true" 
        ads:adUnitId="11111"/> 
</RelativeLayout> 

在我的片段,我有一個列表視圖之一,問題是AdView中顯示了在底部的列表視圖,我該如何解決這個問題?我希望adView能佔用它的空間。 (圖片鏈接顯示情況:https://www.dropbox.com/s/ci5bs67z55d247m/Screenshot_2014-09-13-10-55-38.png?dl=0)。

有什麼建議嗎?

回答

2

只需在DrawerLayout之外移動AdView,然後更改DrawerLayout,以便與AdView共享高度,而不是將其全部消耗。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:id="@+id/outer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

    <android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    > 
    ... 
    </android.support.v4.widget.DrawerLayout> 

    <com.google.android.gms.ads.AdView android:id="@+id/adView" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        ads:adSize="BANNER" 
        android:layout_alignParentBottom="true" 
        ads:adUnitId="ca-app-pub-3875318646278278/2314532545"/> 

</LinearLayout> 
+0

我該怎麼做?我無法將抽屜佈局高度設置爲wrap_content,因爲它引發了一個異常 – slash89mf 2014-09-14 08:13:02

+0

您得到了什麼錯誤?使用LinearLayout而不是RelativeLayout,併爲您的DrawerLayout設置layout_weight =「1」。 – William 2014-09-14 21:34:55

+0

與這個佈局我得到這個結果:https://www.dropbox.com/s/kdkh9bim2teaiz5/Screenshot_2014-09-14-23-48-29.png?dl=0 – slash89mf 2014-09-14 21:49:52