0

I'm working on app which is tutorial based app. I want to show my tutorials as well as banner ad at bottom I want to show tutorial on whole screen until ad is not loaded as soon as ad loads i want my tutorial to shift upside and show ad without overlapping. now I'm using this code but when ad is loading or user not connected to internet the layout for ad takes 50dp area of my screen.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
    >
<ScrollView 
     android:layout_width="match_parent"
     android:layout_height="match_parent"
    android:background="#98FB98"
    android:layout_above="@+id/ad_layout" >

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/title_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_name"
        android:textSize="25sp"
        android:layout_gravity="center"
        android:gravity="center"
        android:padding="10dp"
        android:textColor="@drawable/blue"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/desc_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="left"
        android:padding="10dp"
        android:paddingTop="15dp"
        android:text="@string/content_not_found"
        android:textSize="16sp" />

</LinearLayout>

</ScrollView>
<RelativeLayout 
    android:id="@+id/ad_layout"
    android:layout_height="50dp"
    android:layout_width="fill_parent"
    android:layout_alignParentBottom="true"
    android:background="#98FB98" />
</RelativeLayout>
akshay bhange
  • 2,320
  • 2
  • 28
  • 46
  • you may want to check my response on admob here http://stackoverflow.com/questions/5507516/admob-and-how-does-it-work/32963340#32963340 – justLearning Oct 06 '15 at 10:56

1 Answers1

0

First, you should add admob xml codes in your xml file. Then, in your java file you should check whether the user is connected to the Internet, or not. Then you just put the admob java codes where the Internet exist.

Here is the sample xml file:

<com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="MY_AD_UNIT_ID"
                     ads:adSize="BANNER"
                     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                     ads:loadAdOnCreate="true"/>

Here is the sample java file:

private static final String TEST_DEVICE_ID = "INSERT_YOUR_TEST_DEVICE_ID_HERE";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// networkDetails is a function that checks the Internet is exist or not
if (networkDetails.isEmpty()) {
   setContentView(R.layout.main);
   adView.setVisibility(View.GONE);
}
else{
setContentView(R.layout.main);
        AdView adView = (AdView) this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice(TEST_DEVICE_ID)
            .build();
        adView.loadAd(adRequest);}
    }`
Jaky71
  • 162
  • 1
  • 9
  • but it will overlap my contents. I want an ad that will load in background and till that user will use full screen as soon as ad loads it must push my contents upward and show ad without overlapping – akshay bhange Jul 21 '14 at 15:29
  • I think, you can call the ad view in your full screen codes or `View.GONE` can not take any space till you make it `View.VISIBLE`. Whenever you want to show the ad, just set the ad as visible. – Jaky71 Jul 21 '14 at 20:23
  • will it overlap my contents or shift them up? – akshay bhange Jul 23 '14 at 12:08
  • No, it wont overlap your content or wont shift them up. If you use `View.INVISIBLE`, this will take space as you declared but `View.GONE` doesnt take ANY space. Just try both of them. http://stackoverflow.com/questions/11556607/android-difference-between-invisible-and-gone – Jaky71 Jul 23 '14 at 12:47