将 Admob 添加到 ScrollView ->广告横幅消失
嘿伙计们 到目前为止,我成功地将 Admob 实现为正常的线性布局。 现在我添加了一个额外的 scrollview
并且 adbanner
消失了。我不知道我能做什么来对抗它。
遵循我添加了 scrollview
的 .xml 中的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="match_parent">
<ScrollView android:id="@+id/scrollView1" android:layout_height="wrap_content" android:layout_width="match_parent">
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
[whole bunch of layout elements whoch shouldn´t affect the adbanner]
</LinearLayout>
</ScrollView>
在我的线性布局中,adbanner 仍然有效,整个 adbanner 位置是在主 activitiy.java 文件中完成的(在 taiic.com 教程的帮助下完成此操作)
// Lookup R.layout.main
LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
String pubID = "xxxxxxxxxxxxxxxxxx";
AdView adView = new AdView(this, AdSize.BANNER, pubID);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
任何人都可以告诉我要更改什么或添加什么代码在 scrollview
中实现 admob 横幅?
编辑:
添加
<com.admob.android.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapprimaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
android:alignParentBottom="true"/>
我尝试在 .xml 中的最后两行之间
</LinearLayout>
[here]
</ScrollView>
,但随后收到错误“错误:解析 XML 时出错:未绑定前缀”
欢呼
Hey folks
I managed to implement Admob into a normal linear layout so far.
Now I added a additional scrollview
and the adbanner
disappeared. I don´t know what I can do against it.
Follows the code from the .xml where I added the scrollview
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="match_parent">
<ScrollView android:id="@+id/scrollView1" android:layout_height="wrap_content" android:layout_width="match_parent">
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
[whole bunch of layout elements whoch shouldn´t affect the adbanner]
</LinearLayout>
</ScrollView>
In my linear layout ,where the adbanner still works, the whole adbanner position was done in the main activitiy.java file (did this with help of the tutorial at taiic.com)
// Lookup R.layout.main
LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
String pubID = "xxxxxxxxxxxxxxxxxx";
AdView adView = new AdView(this, AdSize.BANNER, pubID);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
Can anybody tell me what to change or what code to add when implementing an admob banner into a scrollview
?
edit:
i tried to add
<com.admob.android.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapprimaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
android:alignParentBottom="true"/>
between last two lines in the .xml
</LinearLayout>
[here]
</ScrollView>
but then im getting the error "error: Error parsing XML: unbound prefix"
cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于解析错误:
这是问题中的拼写错误吗?
myapprimaryTextColor="#FFFFFF"
而不是myapp:primaryTextColor="#FFFFFF"
。这会给你带来 xml 解析错误。关于布局:
使用RelativeLayout。 工作代码位于帖子末尾。首先,一些理论:)
您的 ScrollView 占据了整个屏幕,这就是您看不到 admob 视图的原因。定义滚动视图后,所有屏幕都对其可用,因此它会占用它。 admob 视图实际上绘制在屏幕下方。它可以在这个例子中重现:
非工作布局
如果您使用RelativeLayout,您可以对其进行设置,以便admob与屏幕底部对齐,滚动视图在其上方,剩余的可用空间。
工作布局
About the parsing error:
Is this a typo in the question?
myapprimaryTextColor="#FFFFFF"
instead ofmyapp:primaryTextColor="#FFFFFF"
. This would give you the xml parse error.About the layouts:
Use a RelativeLayout. The working code is at the end of the post. First, some theory :)
Your ScrollView is taking the whole screen, that's why you don't see the admob view. When the scrollview is defined, all the screen is availabel to it, so it takes it. The admob view is actually drawn below your screen. It can be reproduced in this example:
non-working layout
If you use a RelativeLayout instead, you can set it up so the admob is aligned to the bottom of the screen, and the scrollview above it, taking the rest of the available space.
working layout
我使用了 admob xml 版本,这就是我所使用的并且它有效。广告位于顶部。只需复制并粘贴,您很快就会滚动。
I used the admob xml version and that is what I use and it works. The ad is at the top. Just copy and paste and you will be scrolling along shortly.