Android - How to Add Banner in Custom Position?

Android - How to Add Banner in Custom Position?

Fist you need to add to your layout a ‘container’ where the banner will be attached to later programmatically. This container can be any view that inherits from android ‘ViewGroup’. You also must assign some id to this view that will be later used to ad banner to this view. For example in this layout named ‘activity_advance_banner’ you could add a simple ‘FrameLayout’ that is also a ‘ViewGroup’ between other layout elements in vertical ‘LinearLayout’:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
android:orientation="vertical">

        <ImageView
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:layout_gravity="center_horizontal"
           
android:adjustViewBounds="true"
           
android:scaleType="centerInside"
           
android:src="@drawable/jake_is_amazed" />
   
        <FrameLayout
           
android:id="@+id/bannerContainer"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content" />
   
        <ImageView
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:layout_gravity="center_horizontal"
           
android:adjustViewBounds="true"
           
android:scaleType="centerInside"
           
android:src="@drawable/amazed_medium" />

</LinearLayout>



Then inside the code after this layout have been added to the screen you just have to use Appmediation method AMBanner.showInView passing to it as arguments your activity and container ID. In case of code above it should look like this


@Override
protected void onCreate(Bundle savedInstanceState) {
   
super.onCreate(savedInstanceState);
   
setContentView(R.layout.activity_advance_banner);
   
AMBanner.loadInView(this, R.id.bannerHolder);
}