문제

I want to implement the ads in my app but I want to implement the ads on an overlay view, The main content of the app should be foreground and the overlay is top of the main content and I want to align the overaly at the bottom of the screen. Kindly tell me how I can achieve the overlay at the bottom of my screen???

도움이 되었습니까?

해결책

The simplest way to achieve this is to use a FrameLayout as your root view. Here is some code to demonstrate this. I haven't tested this particular example, but it should work with slight modification to the AdView attributes.

<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <LinearLayout
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <!-- Your main layout code goes here -->
    </LinearLayout>
    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        ads:adUnitId="MY_AD_UNIT_ID"
        ads:adSize="BANNER"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
        ads:loadAdOnCreate="true"/>
</FrameLayout>

Note the layout_gravity attribute of the AdView; that's what causes it to appear at the bottom of the screen.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top