我想在我的应用底部放置一个AdView。但是,当我测试我的应用时,我看不到广告,也看不到广告。
在我的MainActivity中,我用2个片段替换2个FrameLayouts。所以AdView应该出现在第三个片段之后。
这是我的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();
这里是CardListView片段使用的布局。
<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" />
这是我的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.
答案 0 :(得分:1)
最后,我设法让它发挥作用。问题是广告没有足够的空间来展示。
我的CardListView片段的高度为500dp。太过分了。我把它减少到300dp,我现在可以看到我的Adview了。