简体   繁体   English

无法格式化我的布局

[英]Can't format my layout

I'm trying to place a LinearLayout with a banner ad - at the bottom of a RelativeLayout . 我正在尝试将带有横幅广告的LinearLayout放置在RelativeLayout的底部。

I'm trying to achieve it by: 我正在尝试通过以下方式实现这一目标:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".AllJokes" >

    <ListView
              android:id="@+id/allJokesList"
              android:layout_height="wrap_content"
              android:layout_width="match_parent">
    </ListView>

    <LinearLayout 
            android:layout_alignParentBottom="true" 
            android:id="@+id/adViewContainer"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content">

              <com.google.android.gms.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"/>
    </LinearLayout>

</RelativeLayout>

But it always gives me this error: 但这总是给我这个错误:

error: Error parsing XML: unbound prefix

I know that my formatting is completely messed up, but I can't find a way to make it valid. 我知道自己的格式完全搞砸了,但是我找不到使它有效的方法。

I just need a clue, as I'm a total beginner at android and xml. 我只需要一个线索,因为我是android和xml的入门者。 I'm missing something really small I know it. 我想念的东西很小。

You need to have the below in the root element of xml layout 您需要在xml布局的根元素中包含以下内容

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

Like 喜欢

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

coz you have 因为你有

ads:adUnitId="MY_AD_UNIT_ID" // see this attribute 

You're missing a trailing '>' for your LinearLayout. 您在LinearLayout中缺少尾部的'>'。 So that part should be: 因此,该部分应为:

<LinearLayout 
    android:layout_alignParentBottom="true" 
    android:id="@+id/adViewContainer"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM