简体   繁体   English

Admob和ListActivity

[英]Admob and ListActivity

I have asked this question before but didn't get a "good enough" answer. 我之前曾问过这个问题,但没有得到“足够好”的答案。

My problem basically is that I can't get Admob to show correctly in a ListActivity. 我的问题基本上是我无法让Admob在ListActivity中正确显示。

My layout looks like this: 我的布局如下所示:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:myapp="http://schemas.android.com/apk/res/se.javalia.myDrinks"
    android:orientation="vertical">
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
        <ListView android:id="@+id/android:list" android:layout_alignParentTop="true"
            android:layout_width="fill_parent" android:layout_height="wrap_content" />
        <TextView android:id="@+id/android:empty"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:text="@string/main_no_items" />
    </LinearLayout>
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" >
        <com.admob.android.ads.AdView android:id="@+id/ad"
            android:layout_alignParentBottom="true"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
            myapp:secondaryTextColor="#CCCCCC"
            myapp:keywords="drink alcohol wiskey rum soda" myapp:refreshInterval="300" />
    </LinearLayout>
</RelativeLayout>

The problem right now is that if I change the layout_hight to fill_parent or attempt a value larger than 150 px the ad wont show. 现在的问题是,如果我将layout_hight更改为fill_parent或尝试使用大于150像素的值,则广告将不会展示。 With a layout_hight of 150 or less it shows nicely. 如果layout_hight为150或更小,则显示效果很好。 The goal is to get the list to fill the screen after the ad has taken its place. 目标是在广告取代之后,将列表填充到屏幕上。

Any suggestions? 有什么建议么? I'm quite lost about how to solve this. 我对如何解决这个问题非常迷惑。

I will update the question if the answer didn't get all the way so please check for updates. 如果答案没有完全解决,我将更新问题,因此请检查是否有更新。

Thanks in advance Roland 预先感谢罗兰

使用一个RelativeLayout作为外部包装,然后将listview设置为上层父级,将adview设置为下层父级。

I had this problem and was very difficult to find answers in internet. 我遇到了这个问题,很难在互联网上找到答案。 But i had luck, and I found an answer that worked for me. 但是我很幸运,我找到了一个对我有用的答案。

Please remove in your code android:layout_height="wrap_content" and add these two new lines into your Listview 请在您的代码中删除 android:layout_height =“ wrap_content” 并将这两行添加到您的Listview

android:layout_height="0dip"
android:layout_weight="1"

Your Listview code should look like this 您的Listview代码应如下所示

<ListView 
        android:id="@+id/android:list" 
        android:layout_alignParentTop="true"
        android:layout_width="fill_parent" 

        android:layout_height="0dip"
        android:layout_weight="1"
/>

I hope that works for you. 希望对您有用。

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

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