Search code examples
androidcustom-viewadview

How to display adview on other view(custom view) in android


How to display adview on other view(custom view) in android ? I need to play ads on custom view. This is the xml I am using.

<RelativeLayout>

<Button
android:id="@+id/btnmenu"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:text="Menu"
android:typeface="sans"
android:textStyle="bold|italic"
android:gravity="center"
android:textColor="@drawable/white"
android:layout_gravity="center_horizontal"
>
</Button>

<com.google.ads.AdView 
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="XXXXXXXX"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>

<view
class="com.android.MainScreen" 
android:id="@+id/note"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/btnmenu"
android:padding="10dip"
android:scrollbars="vertical"
android:fadingEdge="vertical" />

</RelativeLayout>  

Any help would be appreciated.


Solution

  • Try moving your AdView below your custom view in the XML file. It may be drawing the custom view on top of the AdView. You'll also want to set the AdView's position below the button like you are doing with your custom view with android:layout_below="@+id/btnmenu".

    <view
    class="com.android.MainScreen" 
    android:id="@+id/note"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/btnmenu"
    android:padding="10dip"
    android:scrollbars="vertical"
    android:fadingEdge="vertical" />
    
    <com.google.ads.AdView 
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/btnmenu"
    ads:adUnitId="XXXXXXXX"
    ads:adSize="BANNER"
    ads:loadAdOnCreate="true"/>