Reputation: 465
I am trying to put an AdView at the bottom of my app. However, when I test my app, I don't see the ad, nor the AdView.
In my MainActivity, I am replacing the 2 FrameLayouts with 2 fragments. So the AdView should appear after the third fragment.
Here's my main_activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_id"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/fragment_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/fragment_content2"
android:layout_width="fill_parent"
android:layout_height="500dp" />
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="app_id"/>
</LinearLayout>
Main_activity.java
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("5554:Perfect_One")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
myContext = this;
fragmentManager = this.getFragmentManager();
Fragment frag = new SortFeature();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.fragment_content, frag);
ft.commit();
Fragment frag2 = new CardListView();
FragmentTransaction ft2 = fragmentManager.beginTransaction();
ft2.replace(R.id.fragment_content2, frag2);
ft2.commit();
Here's the layout used by the CardListView fragment.
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="@drawable/background" />
Here's my logcat:
09-08 21:22:29.578: I/Ads(2050): JS: Creating Application Cache with manifest http://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.appcache (http://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html:0)
09-08 21:22:29.588: I/chromium(2050): [INFO:CONSOLE(0)] "Creating Application Cache with manifest http://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.appcache", source: http://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
09-08 21:22:29.618: I/Ads(2050): JS: Application Cache Checking event (http://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html:0)
09-08 21:22:49.629: W/Ads(2050): Not enough space to show ad. Needs 320x50 dp, but only has 320x0 dp.
Upvotes: 0
Views: 554
Reputation: 465
Finally, I managed to make it work. The problem was that there was not enough space for the ad to be shown.
The height of my CardListView fragment was 500dp. It was too much. I reduced it to 300dp and I can now see my Adview proprely.
Upvotes: 1