我有这个项目,我已经把adob放在上面,但广告必须始终在屏幕的底部,当你在页面上下滚动时,广告必须保持在同一个地方。
由于广告有自己的小滚动视图布局,似乎我在某处做错了什么?我已经在下面放了一个屏幕截图以及布局代码
编辑了homexml代码,但错误
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="@+id/ScrlView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dp"
android:layout_weight="1">
<ScrollView
android:id="@+id/ScrlView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/MainActivity"
android:layout_marginBottom="20dp" >
<LinearLayout
android:id="@+id/layoutForScroll"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
<TextView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:gravity="center"
android:text="Welcome To Ride Count!"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#1E90FF"
android:textStyle="bold" >
</TextView>
<RelativeLayout
android:id="@+id/layoutTextViews_one"
android:layout_width="280dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/smallbox1" >
<TextView
android:id="@+id/txtCountLabel_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="24dp"
android:gravity="center"
android:text="Rides Ridden:"
android:textColor="#1E90FF"
android:textStyle="bold" >
</TextView>
<TextView android:textStyle="bold" android:gravity="center" android:text="0000" android:layout_height="wrap_content"
android:layout_width="match_parent" android:id="@+id/sum"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" android:layout_marginTop="45dp"></TextView>
</RelativeLayout>
<TextView
android:id="@+id/txtFact"
android:layout_width="280dp"
android:layout_height="180dp"
android:layout_gravity="center"
android:layout_marginTop="23dp"
android:background="@drawable/factbox"
android:gravity="center"
android:text="Tap For Fact"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/MainActivity"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="0dp"
android:layout_weight="2">
</LinearLayout>
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
googleads:adSize="SMART_BANNER"
googleads:adUnitId="@string/admob_id" />
</LinearLayout>
广告小组布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ad_catalog_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/banner_bottom" />
<TextView android:id="@+id/status"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:text="" />
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="60dp"
googleads:adSize="IAB_MRECT"
googleads:adUnitId="@string/admob_id" />
</LinearLayout>
home XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backgroundtowers"
android:orientation="vertical"
android:scrollbars="vertical"
android:weightSum="1" >
<ScrollView
android:id="@+id/ScrlView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/MainActivity"
android:layout_marginBottom="20dp" >
<LinearLayout
android:id="@+id/layoutForScroll"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
<TextView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:gravity="center"
android:text="Welcome To Ride Count"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#1E90FF"
android:textStyle="bold" >
</TextView>
<RelativeLayout
android:id="@+id/layoutTextViews_one"
android:layout_width="280dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/smallbox1" >
<TextView
android:id="@+id/txtCountLabel_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="24dp"
android:gravity="center"
android:text="Rides Ridden:"
android:textColor="#1E90FF"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/sum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:gravity="center"
android:text="0000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
<TextView
android:id="@+id/txtFact"
android:layout_width="280dp"
android:layout_height="180dp"
android:layout_gravity="center"
android:layout_marginTop="23dp"
android:background="@drawable/factbox"
android:gravity="center"
android:text="Tap For Fact"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/MainActivity"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp" >
</LinearLayout>
</RelativeLayout>
答案 0 :(得分:1)
将广告的layout_height
和layout_width
更改为wrap_content
以查看是否将其删除。您可能还想尝试使用SMART_BANNER
中的asSize
选项自动调整大小。
AdMob 6.0版中添加了SMART_BANNER
选项。看看https://developers.google.com/mobile-ads-sdk/docs/admob/smart-banners。它更容易使用。
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
googleads:adSize="SMART_BANNER"
googleads:adUnitId="@string/admob_id" />
我使用的是LinearLayout
,因为在这种情况下它更容易一些,但如果您愿意,仍然可以使用RelativeLayout
。我们的想法是将AdView
放在XML中,并使用layout_weight
到布局的其余部分来填充视图。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="@+id/ScrlView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dp"
android:layout_weight="1">
<!-- ... -->
</ScrollView>
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
googleads:adSize="SMART_BANNER"
googleads:adUnitId="@string/admob_id" />
</LinearLayout>
答案 1 :(得分:0)
ScrollView和您的AdView需要在RelativeLayout中成为同行。我已经以这种方式实现了你想要的东西。
RelativeLayout
ScrollView
LinearLayout
AdView