我正在尝试将带有横幅广告的 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/