2012-04-19 91 views
0

我創建了此XML文件,其中列出了不同項目的列表,並且我決定將廣告添加到此列表中,但問題在於廣告包含列表中的第一項並跳轉到第二項直接。任何人都可以告訴我如何覆蓋這個問題?我正在尋找的另一件事是改變這個列表的嚴重性列在右邊而不是左邊。 下面是說明我的問題的圖像: enter image description here在列表中放置廣告

XML文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/list_container" 
    android:measureAllChildren="true" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent"> 

<ListView android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:drawSelectorOnTop="false" 
     android:focusableInTouchMode="true" 
    /> 

<ScrollView android:id="@+id/edit_layout" 
    android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    android:visibility="gone" 
    >  
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="5sp" 
     android:paddingLeft="10sp" 
     android:gravity="right" 
     android:paddingRight="15sp" 
     > 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/list_descption_label" 
      android:gravity="right" 
     /> 
     <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:clickable="true" 
      android:singleLine="true" 
      android:hint="@string/list_descption_label" 
      android:id="@+id/list_description" 
      android:inputType="textUri" 
      /> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/list_username_label" 
      android:gravity="right" 
     /> 
     <AutoCompleteTextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:hint="@string/list_username_label" 
      android:id="@+id/list_username" 
      android:imeOptions="actionNext" 
      /> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/list_password_label" 
      android:gravity="right" 
     /> 
     <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:hint="@string/list_password_label" 
      android:id="@+id/list_password" 
      android:inputType="textVisiblePassword" 
      /> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/list_email_label" 
      android:gravity="left" 
     /> 
     <AutoCompleteTextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:hint="@string/list_email_label" 
      android:id="@+id/list_email" 
      android:inputType="textEmailAddress" 
      android:imeOptions="actionNext" 
      /> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/list_notes_label" 
      android:gravity="right" 
     /> 
     <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:gravity="top|left" 
      android:minLines="5" 
      android:hint="@string/list_notes_label" 
      android:id="@+id/list_notes" 
      android:inputType="textMultiLine" 
      /> 

    </LinearLayout> 

</ScrollView> 
<com.google.ads.AdView 
    android:id="@+id/adView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ads:adSize="BANNER" 
    ads:adUnitId="xxxxxxxxx" 
    ads:loadAdOnCreate="true" > 
</com.google.ads.AdView> 

回答

0

設置列表視圖頭。 與

<com.google.ads.AdView 
    android:id="@+id/adView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ads:adSize="BANNER" 
    ads:adUnitId="xxxxxxxxx" 
    ads:loadAdOnCreate="true" > 
</com.google.ads.AdView> 

創建一個XML佈局它充氣,並把它添加到ListView。

inflater = (LayoutInflater) context.getSystemService(
             Context.LAYOUT_INFLATER_SERVICE); 
View adView = inflater.inflate(R.layout.myAdView, null, false); 
yourListView.addHeaderView(adView); 

關於第二個問題,複製android.R ....你是從SDK利用佈局和改變重力或定製您的adaper。