之前我的广告运行良好并且始终位于屏幕底部,但现在我添加了一个 ScrollView ,并且广告向上移动了一点,位于滚动条的正下方。
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/pattern_carbon_fiber_dark">
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="wrap_content" android:layout_height="339px">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:text="Silent Mode" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/silent_textview"></TextView>
<ToggleButton android:layout_height="wrap_content" android:text="Silent Mode" android:id="@+id/silentbutton" android:layout_width="wrap_content" android:textOff="OFF" android:textOn="ON"></ToggleButton>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Wifi " android:id="@+id/wifi_textview"></TextView>
<ToggleButton android:layout_width="wrap_content" android:text="ToggleButton" android:layout_height="wrap_content" android:id="@+id/wifibutton"></ToggleButton>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/gps" android:id="@+id/gps_textview"></TextView>
<Button android:text="@string/gpsbutton" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/gps"></Button>
<TextView android:layout_width="wrap_content" android:text="@string/bluetooth" android:layout_height="wrap_content" android:id="@+id/bluetooth_textview"></TextView>
<ToggleButton android:layout_width="wrap_content" android:text="ToggleButton" android:id="@+id/bluetooth" android:layout_height="wrap_content"></ToggleButton>
<TextView android:text="@string/brightness" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/screenbrightness_textview"></TextView>
<SeekBar android:layout_height="wrap_content" android:id="@+id/SbBar" android:layout_width="fill_parent" android:max="255"></SeekBar>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="wrap_content" android:layout_width="wrap_content">
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="fill_parent"
ads:adSize="BANNER"
ads:adUnitId="a14ddb1a61b9fb4"
ads:loadAdOnCreate="true"
android:visibility="visible"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_height="wrap_content"
android:layout_alignParentTop="false">
</com.google.ads.AdView>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
请帮忙,谢谢!
编辑:图片
最佳答案
1)您可能会将广告留在 scollview 之外,以便它们始终可见(而不是滚动到屏幕外)
2)广告 View 周围的相对布局的目的是什么?这是其中唯一的 View :只需将其删除,您将获得相同的布局,但性能更好。
根据更新,我建议您尝试此布局(您将需要填写许多空白):
<RelativeLayout
...
>
<AdView
android:id="@+id/adView"
android:layout_alignParentBottom="true"
...
/>
<ScrollView
android:layout_alignParentTop="true"
android:layout_above="@id/adView"
...
>
<LinearLayout
...
>
...
...
</LinearLayout>
</ScrollView>
</RelativeLayout>
基本思想是使用RelativeLayout将AdView广告放置在屏幕底部,然后将ScollView设置为放置在广告上方(这样就不会阻挡广告)并与屏幕顶部对齐。
关于android - ScrollView 移动了 AdMob 广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6208146/