13

私は自分のアプリケーションで Navigation-Drawer を使用しています。そのため、navigation_drawer レイアウトで単一のアクティビティを作成しました。ユーザーがナビゲーション ドロワー メニューからメニュー オプションを選択するたびに、フラグメントを使用してメイン コンテンツ エリア (@+id/content_frame) データを変更しています。問題は、すべての画面にadmob広告を表示したいということです。フラグメントを使用して広告レイアウトを初期化し、FrameLayoutに膨らませることができましたが、良いオプションではないと思います.その単一のアクティビティを使用して広告を初期化する方法はありますか?

navigation_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<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" >

    <!-- The main content view -->

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- The navigation drawer -->

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/side_navigation_background"
        android:cacheColorHint="#00000000"
        android:choiceMode="singleChoice"
        android:divider="@color/side_navigation_list_divider_color"
        android:dividerHeight="1dp" />

</android.support.v4.widget.DrawerLayout>
4

2 に答える 2

34

DrawerLayout 内で任意のレイアウトを使用できます。以下に示す .xml では、このアクティビティの下部にある admob ad を使用して、(RelativeLayout を使用して) 単一のアクティビティでフラグメントを切り替えることができます。

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

        <RelativeLayout
            android:id="@+id/relative_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <FrameLayout
                android:id="@+id/fragment"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@+id/adView"
                android:background="@color/background" />

            <com.google.android.gms.ads.AdView
                android:id="@+id/adView"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                ads:adSize="SMART_BANNER"
                ads:adUnitId="AD_UNIT_IT"
                ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                android:gravity="bottom" />
        </RelativeLayout>

        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@color/white"
            android:choiceMode="singleChoice"/>
</android.support.v4.widget.DrawerLayout>
于 2013-06-22T07:59:45.090 に答える