com.google.ads.AdView无法实例化错误

时间:2013-12-02 16:27:08

标签: android xml listview layout

我尝试了很多东西,却无法做到。我尝试时,应用程序总是崩溃。我希望广告位于屏幕底部,滚动到底部时不会覆盖最后一个列表视图项目。

这是我的xml,没有广告。编辑:这是最新的代码。我收到com.google.ads.AdView无法实例化错误。我的广告在不同的布局中工作,但是对于这种布局,它们没有显示。

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:orientation="vertical"
     android:layout_weight="1">

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

   <com.google.ads.AdView
        android:id="@+id/ad"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        ads:adSize="BANNER"
        ads:adUnitId="---------------------"
        ads:loadAdOnCreate="true"
        android:gravity="center_horizontal" />
   </LinearLayout>

<FrameLayout
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="@dimen/header_height">

    <com.gains.myapp.KenBurnsView
        android:id="@+id/header_picture"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/picture0" />

    <ImageView
        android:id="@+id/header_logo"
        android:layout_width="@dimen/header_logo_size"
        android:layout_height="@dimen/header_logo_size"
        android:layout_gravity="center"
        android:src="@drawable/ic_header_logo" />

</FrameLayout>

2 个答案:

答案 0 :(得分:0)

将列表视图高度设置为一个值,使其覆盖屏幕的3/4。尝试400,450 dp。

将属性align parent bottom = true设置为admob小部件。这会将你的admob小部件粘贴到底部

答案 1 :(得分:0)

您已将ListView配置为使用其父级的所有高度,而不留其他任何空间。我建议你尝试更多的东西:

  <Linearayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="0"
        android:layout_weight="1"/>

    <FrameLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="@dimen/header_height">

        <com.gains.myapp.KenBurnsView
            android:id="@+id/header_picture"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/picture0" />

        <ImageView
            android:id="@+id/header_logo"
            android:layout_width="@dimen/header_logo_size"
            android:layout_height="@dimen/header_logo_size"
            android:layout_gravity="center"
            android:src="@drawable/ic_header_logo" />

      </FrameLayout>
  </LinearLayout>

请注意ListView配置中的 android:layout_weight =“1”。这将导致ListView扩展以填充其封闭的LinearLayout中的可用空间。

阅读http://developer.android.com/guide/topics/ui/declaring-layout.html 您需要更好地了解Android布局,何时使用它们以及它们的工作方式。