2012-02-02 27 views
0

我开发了一个android应用程序。我的应用程序将在横向模式下使用。现在我想在左侧垂直放置广告。可能吗?如果没有,那么请如何将它水平放置在顶部?如何在relativelayout中添加admob

我的布局是

<?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> 

回答

0

你需要把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> 
0

由于对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> 
相关问题