2013-07-11 227 views
5

我有一個活動,其中廣告填充從Java代碼填充的動態表,該表具有從網絡異步加載的圖像。當我不包含廣告時,所有事情都按照我的預期工作。但是,當我包含adview以及從網絡異步加載的圖像時,它會掛起UI,直到圖像從網絡加載。與異步數據加載的Adview(admob)

我無法理解的行爲,你可以給我解決方案,圖片應該與adview異步加載。

下面是我的活動代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/linearLayout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    > 

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

    <ScrollView 
     android:id="@+id/scroll1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <TableLayout 
      android:id="@+id/table_layout" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

      <TableRow> 

       <TextView 
        android:id="@+id/left_text" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="0" 
        android:gravity="left|center_vertical" 
        android:padding="5dip" 
        android:text="Code" /> 

       <TextView 
        android:id="@+id/middle_text" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:gravity="right|center_vertical" 
        android:padding="5dip" 
        android:text="Name of Company" /> 

       <TextView 
        android:id="@+id/right_text" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="0" 
        android:gravity="right|center_vertical" 
        android:padding="5dip" 
        android:text="1.3" /> 
      </TableRow> 
     </TableLayout> 
    </ScrollView> 

</LinearLayout> 

感謝

愛瑪

+0

我也面臨同樣的問題。任何人都可以幫忙嗎? – user93796

+0

任何人都可以幫助我們嗎? – user93796

+0

我認爲這需要澄清。什麼和你在哪裏加載任何圖像? –

回答

1

也許你需要的不是加載它的線性佈局在您的內部網絡從你的主要的LinearLayout sepearte AdView的, (異步)活動將會完成。

只需嘗試使用「框架佈局」,並在頂部&的adView上爲LinearLayout使用margin_top「55dp」。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_gravity="top"> 

<com.google.ads.AdView xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/main_adView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    android:gravity="center" 
    ads:adUnitId = "******" 
    ads:adSize = "BANNER" 
    > 

</com.google.ads.AdView> 
</LinearLayout> 

<LinearLayout 
android:id="@+id/linearLayout" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginTop="55dp" 
android:orientation="vertical"> 


<ScrollView 
    android:id="@+id/scroll1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TableLayout 
     android:id="@+id/table_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <TableRow> 

      <TextView 
       android:id="@+id/left_text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="0" 
       android:gravity="left|center_vertical" 
       android:padding="5dip" 
       android:text="Code" /> 

      <TextView 
       android:id="@+id/middle_text" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right|center_vertical" 
       android:padding="5dip" 
       android:text="Name of Company" /> 

      <TextView 
       android:id="@+id/right_text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="0" 
       android:gravity="right|center_vertical" 
       android:padding="5dip" 
       android:text="1.3" /> 
     </TableRow> 
    </TableLayout> 
</ScrollView> 

</LinearLayout> 
</FrameLayout> 

請讓我知道狀態。

0

我對Admob原生廣告有類似的問題。我想在回收站視圖中放置廣告。滾動瀏覽時,當我點擊原生廣告時,用戶界面會凍結,滾動只會在廣告加載後繼續滾動

我做了一些計時,發現loadAd()需要大約1400ms,隨後調用loadAd()的時間下降到150毫秒,所以我的修補程序是創建一個原生廣告剛創建我的片段後:

private static boolean preLoadAd = true; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View rootView = inflater.inflate(R.layout.fragment_help, container, false); 
    cardsAdapter = new CardsAdapter(Cards.cards, this); 
    recyclerView = (RecyclerView) rootView.findViewById(R.id.card_collection); 

    //Pre-load ad to allow smoother scrolling 
    //First time loading a native ad takes 800-1500ms, afterwards around 150ms 
    if (preLoadAd) { 
     //only do this once 
     preLoadAd=false; 
     //add the task to the message cue to run after the help fragment has shown 
     recyclerView.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       try { 
        CardVariations.createNativeAdViewHolder(recyclerView); 
       }catch(Exception e){e.printStackTrace();} 
      }},200L); 
    } 
    return rootView; 
}