我想在页面底部安装横幅,但它与主屏幕中的内容重叠。 在主屏幕中有很多内容并且有滚动。
有谁知道为什么? 感谢。
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidsam="http://schemas.android.com/apk/res/com.jameselsey"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/home_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout <!-- CONTENT LAYOUT HERE -->
android:id="@+id/flContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<!-- Put all your application views here, such as buttons, textviews, edittexts and so on -->
</LinearLayout>
<LinearLayout
android:id="@+id/ad_layout" <!-- AdMob LAYOUT -->
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/home_layout"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
MainActivity.java
// Create an ad.
adView = new AdView(context);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the AdView to the view hierarchy. The view
// will have no size
// until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.ad_layout);
layout.getBottom();
layout.addView(adView);
// Create an ad request. Check logcat output for the
// hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE").build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
答案 0 :(得分:1)
您可以使用相对定位来解决它,例如尝试将above
属性设置为home_layout
.-
<LinearLayout
android:id="@+id/home_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ad_layout"
android:orientation="vertical" >
修改强>
此外,您需要从layout_alignBottom
删除属性ad_layout
。
android:layout_alignBottom="@+id/home_layout"
编辑2
这里有一个基本示例来说明您的场景.-
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/green"
android:layout_above="@+id/banner" />
<LinearLayout
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="200dp"
android:orientation="vertical"
android:background="@color/gray" />
</RelativeLayout>
导致.-
另一种方法是更改垂直RelativeLayout
的根LinearLayout
,如果您坚持使用RelativeLayout
,则应删除orientation
属性。< / p>
答案 1 :(得分:0)
我遇到了同样的问题,我已经用这种方式解决了http://www.ahotbrew.com/how-to-put-admob-banner-on-the-bottom/
创建相对布局并将“android:layout_alignParentBottom =”true“”属性添加到adview中,如示例中所示。给列表一个边距底部,它不会重叠。