AdMob AdView and ViewPager?

后端 未结 2 811
误落风尘
误落风尘 2020-12-30 11:18

I have Android application with ViewPager implemented like this :

http://www.youtube.com/watch?v=C6_1KznO95A

I don\'t know how to implement AdView below the

相关标签:
2条回答
  • 2020-12-30 11:45

    This worked for me.

        AdView adView = (AdView) findViewById(R.id.ad);
        adView.bringToFront();
    
    0 讨论(0)
  • 2020-12-30 11:48

    OK, you have a couple of problems.

    1. orientation is only relevant for a LinearLayout.
    2. layout_alignParentBottom needs a boolean value not "top"
    3. layout_weight is only relevant for a LinearLayout nor RelativeLayout

    You have 2 options. Use a RelativeLayout but define the AdView first with the ViewPager being defined as above it OR use a LinearLayout and have the ViewPager fill the unused space using layout_weight.

    As RelativeLayout

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    >
    
    <com.google.ads.AdView
        android:id="@+id/ad"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/admob_publisher_id"
        ads:loadAdOnCreate="true" />
    
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_alignParentTop="true"
        android:layout_above="@+id/ad"
        />
    
    </RelativeLayout>
    

    OR as LinearLayout

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>
    
    <com.google.ads.AdView
        android:id="@+id/ad"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/admob_publisher_id"
        ads:loadAdOnCreate="true" />
    
    </LinearLayout>
    

    Personally I'd go with the LinearLayout it feels simpler.

    0 讨论(0)
提交回复
热议问题