2012-05-18 2 views
2

내 레이아웃에서 Adview을 테스트하고 있습니다. ListView 앞에 Adview을 배치하면 모든 것이 잘되지만, ListView 후에 배치하면 그냥 나타나지 않습니다.왜 ListView 후에 Adview를 배치 할 수 없습니까?

무엇이 잘못 되었나요?

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

답변

6

당신은 ListViewlayout_heightfill_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" /> 
+0

위대한! 감사합니다 @ K-ballo, 그 코드를 시도했지만 AdView에서 사용해야한다고 생각했습니다. 이제 잘 작동합니다. – eskalera

+0

이것은 UI를 정렬하는 데 사용되지만 광고가로드되고 표시되는 즉시 ListView가 데이터의 아래쪽으로 스크롤됩니다 .-( –

+0

'android : transcriptMode'는 비활성화해야합니다 .-- 이제 더 이상 스크롤하지 않습니다. –

2

당신의 Listview height is fill parent 그래서 당신의 수직 공간은 이미 촬영한다 목록보기 ,,,

그렇게 목록보기 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> 
1

C를 만들 레이아웃을 RelativeLayout으로 변경하고 ListViewandroid:layout_above="@+id/adView"을 추가하십시오. 나는 너를 도울 수 있기를 바란다.

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