首页 文章

如何添加广告 - 暴徒(广告 Banner )Imageview的顶部或底部?

提问于
浏览
0

我有3个线性布局,第一个布局用于图像视图,第二个布局用于两个按钮,即下一个,上一个和第三个我添加 admob 但问题是我的 admob(Advertisement) 占用额外的广告空间但我想显示图像的顶部或底部位置,我如何设置它的XML?

我希望我的广告 Banner 在图像上看起来像这样,而不是占用额外的空间:
enter image description here

我的XML:

<?xml version =“1.0”encoding =“utf-8”? >

<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:gravity="fill"
android:orientation="vertical"
android:weightSum="100">

<ImageView
    android:id="@+id/idImageViewPic"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="100"
    android:adjustViewBounds="true"
    android:background="#000000"
    android:maxHeight="91dip"
    android:maxWidth="47dip"
    android:padding="10dip"
    android:src="@drawable/p1"
     />

<LinearLayout
    android:id="@+id/layout"
    android:layout_width="wrap_content"
    android:layout_height="50dp" 
    >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="aasdf74546adsf"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
         >
    </com.google.ads.AdView>
</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center" 
    >

    <Button
        android:id="@+id/bGeri"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#d6d6d6"
        android:text="Previous"
        android:textStyle="bold" >
    </Button>

    <Button
        android:id="@+id/bIleri"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#d6d6d6"
        android:text="Next"
        android:textStyle="bold" >
    </Button>
</LinearLayout>

2 回答

  • 0

    看看这个,它可能对你有所帮助 .

    创建xml文件,例如 .

    main.xml中

    <merge 
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" >
    
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <ImageView
            android:id="@+id/idImageViewPic"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/p1" />
    
        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            ads:adSize="BANNER"
            ads:adUnitId="a152fe7ceceb49a"
            ads:loadAdOnCreate="true"
            ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" >
        </com.google.ads.AdView>
    </RelativeLayout>
    

    现在将此main.xml文件包含在您的activity_main.xml中 .

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:weightSum="10" >
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="9"
        android:orientation="vertical" >
    
        <include
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            layout="@layout/main" />
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal" >
    
        <Button
        android:id="@+id/bGeri"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#d6d6d6"
        android:text="Previous"
        android:textStyle="bold" >
    </Button>
    
         <Button
        android:id="@+id/bIleri"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#d6d6d6"
        android:text="Next"
        android:textStyle="bold" >
    </Button>
    </LinearLayout>
    

    希望这可以解决您的问题

  • 0

    使用相对布局,并对齐父底部:

    <RelativeLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:background="#000000"
     >
    
    
        <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="aasdf74546adsf"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
         >
    </com.google.ads.AdView>
     </RelativeLayout>
    

相关问题