【发布时间】:2014-08-15 19:06:54
【问题描述】:
如果这个问题已经得到解答,我深表歉意,广泛的谷歌搜索发现我很多类似但不完全相同的情况没有提供答案。我有一个 WebView,想在它下面放一个 Google AdView。但是,我不希望添加始终附加到窗口底部,我希望它出现在 WebView 之后,即我滚动浏览网页的内容,然后在其下方显示广告。我已经尝试了许多相对和线性布局的变体,这里以一种尝试为例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_weight="1"/>
<com.google.android.gms.ads.AdView
android:id="@+id/web_frag_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="myUnitId"
ads:adSize="BANNER" />
</LinearLayout>
我尝试过使用 layout_below 的 RelativeLayout,但 WebView 将其覆盖了。如果我 alignParentBottom 会显示,但这不是我想要的行为。我希望它仅在滚动浏览网页内容后才可见。我确信我犯了一个简单的布局错误,非常感谢帮助我指出正确的方向。
【问题讨论】:
-
我怀疑这将很难实现。我认为您必须跟踪
WebView中的所有滚动移动,然后在用户向底部滚动时在广告中设置动画。如果WebView中的Web 内容是您自己的内容,那么在HTML 中嵌入广告横幅会简单得多。 -
同意,这将很难实现。您必须监视 webview 滚动并具有在滚动后启动
web_frag_ad的功能。我建议您将广告放在 HTML 中,就像 @CommonsWare 建议的那样。
标签: android android-layout webview