Android 如何在relativelayout中添加admob
我开发了一个android应用程序。我的应用程序将在横向模式下使用。现在我想在左侧垂直放置一个广告。可能吗?如果没有,请如何将其水平放置在顶部 我的布局是Android 如何在relativelayout中添加admob,android,admob,android-relativelayout,Android,Admob,Android Relativelayout,我开发了一个android应用程序。我的应用程序将在横向模式下使用。现在我想在左侧垂直放置一个广告。可能吗?如果没有,请如何将其水平放置在顶部 我的布局是 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:id="@+id/s1" android:layout_width="wrap_content"
android:src="@drawable/a_1" android:layout_height="wrap_content"
android:padding="2dp" />
<ImageView android:id="@+id/s2" android:layout_width="wrap_content"
android:src="@drawable/a_2" android:layout_height="wrap_content"
android:padding="2dp" />
<ImageView android:id="@+id/s3" android:layout_width="wrap_content"
android:src="@drawable/a_3" android:layout_height="wrap_content"
android:padding="2dp" />
<ImageView android:id="@+id/s4" android:layout_width="wrap_content"
android:src="@drawable/a_4" android:layout_height="wrap_content"
android:padding="2dp" />
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_alignParentBottom="true"
android:gravity="center" android:background="#00000000">
<TextView android:id="@+id/l" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:paddingLeft="20dp"
android:paddingRight="20dp" android:background="@drawable/letterbackground"
android:textColor="#FFFFFFFF" android:textSize="60sp"
android:shadowColor="#AA42d68b" android:shadowRadius="1.5"
android:shadowDx="5" android:shadowDy="5" android:text="A" />
</RelativeLayout>
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/menu_widget" />
</RelativeLayout>
</RelativeLayout>
您需要将admob AdView放入代码(活动或片段)中。当您收到实际广告时,广告将显示(水平位于顶部) 以下是一个应该有效的示例:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
xmlns:myapp="http://schemas.android.com/apk/res/your.app.package"
android:id="@+id/ad_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
<Put the rest of the layout here>
</Put the rest of the layout here>
</RelativeLayout>
从Admob 6.4.1版开始,您甚至不必实例化活动,您可以直接将广告添加为视图:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.ads.AdView android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="a151b78112c1df4"
ads:testDevices="TEST_EMULATOR,TEST_DEVICE_ID_GOES_HERE"
ads:loadAdOnCreate="true"/>
</RelativeLayout>