Android AdMob在导航抽屉布局中正确显示
我有一个带有admob广告的导航抽屉布局,如下所示:Android AdMob在导航抽屉布局中正确显示,android,admob,navigation-drawer,Android,Admob,Navigation Drawer,我有一个带有admob广告的导航抽屉布局,如下所示: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" android:id="@+id/relative_layout" android:layout_width="match_parent" android:layout_height="
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<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" >
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"
ads:adUnitId="11111"/>
</RelativeLayout>
)
有什么建议吗?只需将AdView移到抽屉布局之外,然后更改抽屉布局,使其与AdView共享高度,而不是全部占用
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/outer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<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:layout_weight="1"
>
...
</android.support.v4.widget.DrawerLayout>
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"
ads:adUnitId="ca-app-pub-3875318646278278/2314532545"/>
</LinearLayout>
...
我该怎么做?我无法将抽屉布局高度设置为包装内容,因为这会引发异常。您遇到了什么错误?使用LinearLayout而不是RelativeLayout,并为您的抽屉布局设置layout_weight=“1”。通过此布局,我得到了以下结果:当导航抽屉放置在抽屉布局中时,AdView似乎带走了导航抽屉的单击事件。对我来说,解决方案是将抽屉布局和其中的所有内容包装成一个相对的布局,并将AdView保留在抽屉布局之外,但保留在RealtiveLayout内部。执行此操作时,还可以使用alignParentBottom=true放置AdView,这符合我的要求。