Sarthakpandit Sarthakpandit - 9 days ago 5
Android Question

place an ad on top of layout in android

Mobile ad does not get positioned on the top of the layout ,like the ad placed at the bottom .It is not overlapping the layout.

here is the image of the layout,and what i am talking about,have a look
Image of the layout

here is the xml code for it

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.dancing.dance.girl"
android:background="@mipmap/vsdv">


<com.google.android.gms.ads.AdView
android:id="@+id/abovebeauty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="@string/dancinggirl">
</com.google.android.gms.ads.AdView>



<!-- TODO: Update blank fragment layout -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:id="@+id/beauty_fragment"
android:orientation="vertical"
android:padding="10dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >

<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="@+id/1"
android:layout_weight="1"
android:src="@drawable/lob"
android:background="@null"
android:scaleType="fitXY"


android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp" />
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="@+id/2"
android:layout_weight="1"
android:src="@drawable/lob"
android:background="@null"
android:scaleType="fitXY"


android:layout_marginTop="20dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="5dp" />




</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >

<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/lob"
android:background="@null"
android:scaleType="fitXY"
android:id="@+id/3"

android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="5dp" />



<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/lob"
android:background="@null"
android:scaleType="fitXY"
android:id="@+id/4"

android:layout_marginTop="5dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="20dp" />
</LinearLayout>

</LinearLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/beautyfragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/dancinggirl">
</com.google.android.gms.ads.AdView>
</RelativeLayout>


Thankyou for looking at it.

Answer

try this way

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.dancing.dance.girl"
android:background="@mipmap/vsdv">






<!-- TODO: Update blank fragment layout -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="2"
    android:id="@+id/beauty_fragment"
    android:orientation="vertical"
    android:padding="10dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="2" >

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/1"
            android:layout_weight="1"
            android:src="@drawable/lob"
            android:background="@null"
            android:scaleType="fitXY"


            android:layout_marginLeft="20dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="5dp" />
        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/2"
            android:layout_weight="1"
            android:src="@drawable/lob"
            android:background="@null"
            android:scaleType="fitXY"


            android:layout_marginTop="20dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="20dp"
            android:layout_marginBottom="5dp" />




    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="2" >

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/lob"
            android:background="@null"
            android:scaleType="fitXY"
            android:id="@+id/3"

            android:layout_marginLeft="20dp"
            android:layout_marginRight="5dp"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="5dp" />



        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:src="@drawable/lob"
            android:background="@null"
            android:scaleType="fitXY"
            android:id="@+id/4"

            android:layout_marginTop="5dp"
            android:layout_marginRight="20dp"
            android:layout_marginLeft="5dp"
            android:layout_marginBottom="20dp" />
    </LinearLayout>

</LinearLayout>

 <com.google.android.gms.ads.AdView
    android:id="@+id/abovebeauty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/dancinggirl">
</com.google.android.gms.ads.AdView>

<com.google.android.gms.ads.AdView
    android:id="@+id/beautyfragment"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/dancinggirl">
</com.google.android.gms.ads.AdView>

Comments