【发布时间】:2015-12-24 02:30:53
【问题描述】:
我已经根据Get Started 指南实施了 Admobs。 我的应用程序的主要活动布局中有一个 DrawerLayout。 对于每个视图,广告都会正确显示在屏幕底部。
但是,列表视图不会调整大小以适应广告,因此广告会遮挡列表项。
我试过this solution; 但是在任何视图中都没有显示任何广告
我尝试了另一种 SO 解决方案,将相对布局更改为线性布局,但这也不起作用。
这是我的 activity_main 布局:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:gravity="bottom">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
<ExpandableListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:background="@color/list_background"
android:groupIndicator="@android:color/transparent"/>
</android.support.v4.widget.DrawerLayout>
这是我在 Main 中用来展示广告的代码:
setContentView(R.layout.activity_main);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
这是一个带有列表视图的片段的示例布局文件,它将进入框架布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/material_lightgreen_50" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="48dp"
android:background="@color/material_lightgreen_100"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp" >
<TextView
android:id="@+id/tv_pagetitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="@color/material_lightgreen_500"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginLeft="10dp" />
<TextView
android:id="@+id/tv_stepview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:gravity="right"
android:textColor="@color/material_lightgreen_500"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="@string/emptylist" />
如何让listview尾部向上移动,让广告可以在下方展示?
【问题讨论】:
-
你最好贴一张你的问题的图片。
-
尝试添加 android:scaleType="fitxy" ?
标签: android android-layout android-fragments admob