java - 无法格式化我的布局

标签 java android xml

我正在尝试将带有横幅广告的 LinearLayout 放置在 RelativeLayout 的底部。

我试图通过以下方式实现它:

<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>

但它总是给我这个错误:

error: Error parsing XML: unbound prefix

我知道我的格式完全困惑,但我找不到使其有效的方法。

我只需要一个线索,因为我是 android 和 xml 的初学者。我知道我错过了一些很小的东西。

最佳答案

您需要在 xml 布局的根元素中包含以下内容

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

喜欢

<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"

因为你有

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

关于java - 无法格式化我的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22743053/

相关文章:

ruby - 如何在恢复模式下运行 ruby​​ SAX 解析器?

java - 使用 Xstream 将具有对象列表的 XML 解析为 javaobject

java - 是否可以通过编程方式创建 Freemarker 宏?

java - 多项式导数处理指数为0

java - 为什么我收到 @Provides-annotated 错误?

java - DVM确保多个实例在单个设备上高效运行!这意味着什么?

java - 如何管理 QuickBooks XML 的额外 xml 声明

java - 我的 Singleton 类的 Spring 和 IoC(网络应用程序,Tomcat)

java - 是否可以使用java更改谷歌云存储文件的文件名?

android - 改造错误: Expected BEGIN_OBJECT but was BEGIN_ARRAY