Android Overlay at bottom of the screen

假如想象 提交于 2019-12-23 02:20:20

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/19129992/android-overlay-at-bottom-of-the-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!