简体   繁体   中英

Android banner Ad layout

My page has a footer containing navigation image buttons (back and forwards) defined as a RelativeLayout .

<!-- Footer aligned to bottom. This is for the menu -->
<RelativeLayout
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@drawable/bottom_menu_bgd"
    android:paddingLeft="30dp"
    android:paddingRight="30dp">

<ImageButton
    android:id="@+id/bottom_menu_btn_home"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:background="@null"
    android:src="@drawable/bottom_menu_home"/>

<ImageButton
    android:id="@+id/bottom_menu_btn_play"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:background="@null"
    android:src="@drawable/bottom_menu_play"
    android:visibility="visible"/>
</RelativeLayout>

I want to add a banner Ad just on the top of the footer. I have tried to insert a LinearLayout (used the banner Ad) in the RelativeLayout but it showed the banner on the same position of the footer.

How can I move the banner Ad in order to be showed just on the top of footer ?

Put your Banner AdView at end of RelativeLayout and make it above footer layout by adding android:layout_above="@+id/footer" to AdView

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Footer aligned to bottom. This is for the menu -->
    <RelativeLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentBottom="true"
        android:background="@drawable/bottom_menu_bgd"
        android:paddingLeft="30dp"
        android:paddingRight="30dp">

        <ImageButton
            android:id="@+id/bottom_menu_btn_home"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:background="@null"
            android:src="@drawable/bottom_menu_home"/>

        <ImageButton
            android:id="@+id/bottom_menu_btn_play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:background="@null"
            android:src="@drawable/bottom_menu_play"
            android:visibility="visible"/>
    </RelativeLayout>



    <!-- Add your Banner AdView here  -->

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_above="@+id/footer"    
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111"/>


</RelativeLayout>

You can apply weights to all your layouts. Assign weight_sum = 10 to your parent layout. and then

layout_weight="8" ---to layout above footer,
layout_weight = "1" ---to footer
layout_weight = "1" ---to banner ad

Try using this Demo code It will contain two button at bottom of screen and Adview above bottom images:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/action_bar_hover"
    android:paddingLeft="30dp"
    android:paddingRight="30dp">


    <RelativeLayout
        android:id="@+id/my_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">


        <ImageButton
            android:id="@+id/bottom_menu_btn_home"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:background="@null"
            android:src="@android:drawable/alert_dark_frame" />

        <ImageButton
            android:id="@+id/bottom_menu_btn_play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:background="@null"
            android:src="@android:drawable/alert_dark_frame"
            android:visibility="visible" />


    </RelativeLayout>


    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="MEDIUM_RECTANGLE"
        android:layout_above="@id/my_view"
        ads:adUnitId="@string/banner_home_footer"/>


</RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM