我正在针对手机和平板电脑定位我的应用。我在fragments.xml
和/layout
上创建了/layout-land
。
在管理片段的类中,我把它放在:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragments);
adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
if (findViewById(R.id.fragmentsboth) != null) {
numberOfPanes = 1;
if (savedInstanceState != null) {
return;
}
QueryFragment firstFragment = new QueryFragment();
getSupportFragmentManager().beginTransaction().add(R.id.fragmentsboth, firstFragment).commit();
} else if (savedInstanceState == null) {
QueryFragment firstFragment = new QueryFragment();
getSupportFragmentManager().beginTransaction().add(R.id.fragment_one, firstFragment).commit();
if (operation != 5) {
Infodata secondFragment = new Infodata();
getSupportFragmentManager().beginTransaction().add(R.id.fragment_two, secondFragment).commit();
} else {
Compare secondFragment = new Compare();
getSupportFragmentManager().beginTransaction().add(R.id.fragment_two, secondFragment).commit();
}
}
}
我已将AdView
添加到我的fragments.xml
,并且正在预期的电话上工作。广告就是展示。
在平板电脑上,我可以看到广告的空间,但没有显示添加内容。
以下是平板电脑fragments.xml
的代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lightgrey">
<LinearLayout
android:id="@+id/fragment_container"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lightgrey"
android:baselineAligned="false">
<LinearLayout
android:id="@+id/fragment_one"
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:background="@color/lightgrey">
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:baselineAligned="false">
<LinearLayout
android:id="@+id/fragment_two"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/lightgrey"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="12121212"
ads:adSize="SMART_BANNER"
android:layout_gravity="center|bottom"
android:layout_alignParentStart="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/orange"
android:dividerHeight="1dp"
android:listSelector="@drawable/menulist_selector"
android:background="@color/lblack"/>
</android.support.v4.widget.DrawerLayout>
为什么广告没有显示?
答案 0 :(得分:2)
当LogCat显示如下内容时:
WARN/Ads(3805): Not enough space to show ad! Wants: <xxx, xx>, Has: <xxx, xx>.
表示广告没有空间可供展示。您的Layout
占据了视图的所有高度。因此,即使您在layot中指定了AdView,它也会达到0高度。