我在this Google支持页面上看到,广告与应用内容重叠是违反政策的,并且广告应该与带边框的内容分开。
目前,以下是我在我的应用中展示横幅广告的方式。我认为这会导致违反政策,广告与我的内容重叠(即使重叠的屏幕部分为空白)。
activity_main.xml
:
<?xml version="1.0" encoding="utf-8"?>
<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/fragmentDrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Main content -->
<RelativeLayout
android:id="@+id/fragmentDrawerContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!-- Banner ad -->
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_ad_unit_id"/>
</FrameLayout>
<!-- Navigation drawer -->
<ListView android:id="@+id/fragmentLeftDrawer"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:textStyle="bold"
android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>
问题:我对xml布局不太满意。如何修复activity_main.xml
的布局,使其看起来像下面的推荐布局?我会使用布局权重还是其他方法?
提前谢谢你。我很感激所有的建议。
答案 0 :(得分:0)
您可以使用LinearLayout而不是FrameLayout,方向设置为垂直,以使内容一个接一个地流动,而不是一个在另一个之上。
<?xml version="1.0" encoding="utf-8"?>
<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/fragmentDrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
orientation="vertical">
<!-- Main content -->
<RelativeLayout
android:id="@+id/fragmentDrawerContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="100" />
<!-- Banner ad -->
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_ad_unit_id"/>
</LinearLayout>
<!-- Navigation drawer -->
<ListView android:id="@+id/fragmentLeftDrawer"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:textStyle="bold"
android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>
使用0dp
作为布局高度和权重100
会告诉LinearLayout先计算AdView的大小,然后用RelativeLayout填充剩余的空间。
(在这种特殊情况下,权重可能是任何非零值,因为我们没有给AdView任何权重。)
有关布局权重的更多信息,您可以在他的StylingAndroid博客上查看Mark Allison的教程: