2

レイアウトでテストしAdviewています。Adview前に配置するとListViewすべて問題ありませんが、後に配置するとListView表示されません。

どうしたの?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="bottom"
        android:background="@android:color/white" />

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="xxxx"
        ads:testDevices="xxxx" />

</LinearLayout>
4

3 に答える 3

6

ListView'slayout_heightをに設定するfill_parentと、レイアウト内の残りのすべての垂直スペースが使用されます。あなたAdViewはそこにいます、それはちょうどによって画面の外に移動されましたListView

AdViewを下部に配置し、残りのすべてListViewの垂直スペースを取得する場合は、ウェイトを使用して行うことができます。

<ListView
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@android:color/white" />
于 2012-05-18T17:18:13.040 に答える
2

あなたListview height is fill parentの垂直方向のスペースはすでにlistviewによって取得されています、、、

だからリストビューを作るandroid:layout_weight="1"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ListView android:layout_weight="1"
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="bottom"
        android:background="@android:color/white" />

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="xxxx"
        ads:testDevices="xxxx" />

</LinearLayout>
于 2012-05-18T17:19:09.327 に答える
1

レイアウトをに変更してRelativeLayout、に追加android:layout_above="@+id/adView"しますListView。お役に立てば幸いです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/list_view"
        android:layout_above="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@null" />

    <com.google.android.gms.ads.AdView 
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="xxxxx" />

</RelativeLayout>
于 2017-07-19T03:04:44.337 に答える