2013-07-11 37 views
5

Tôi có một hoạt động nơi quảng cáo được điền trên bảng động được điền từ mã java, bảng này có hình ảnh được tải từ mạng không đồng bộ. Khi tôi không bao gồm quảng cáo mọi thứ hoạt động như mong đợi đối với tôi. Nhưng khi tôi bao gồm adview cũng như các hình ảnh tải từ mạng không đồng bộ, nó treo UI cho đến khi các hình ảnh được tải từ mạng.Adview (admob) với tải dữ liệu không đồng bộ

Tôi không thể hiểu hành vi, Bạn có thể vui lòng cho tôi giải pháp nơi hình ảnh sẽ tải không đồng bộ cùng với adview hay không.

Dưới đây là mã hoạt động của tôi:

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

Cảm ơn

Amandeep

+0

cũng phải đối mặt với cùng một vấn đề.Bất cứ ai có thể giúp bạn? – user93796

+0

Có ai giúp chúng tôi với điều này không? – user93796

+0

Tôi nghĩ rằng điều này cần làm rõ. Bạn đang tải bất kỳ hình ảnh nào và ở đâu? –

Trả lời

1

Có lẽ bạn cần phải sepearte các adview từ LinearLayout chính của bạn, thay vì tải nó bên Linear Layout nơi mạng của bạn (hoạt động không đồng bộ) sẽ được thực hiện.

Chỉ cần thử sử dụng Bố cục khung, với adView ở đầu & với margin_top của "55dp" cho LinearLayout.

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

Vui lòng cho tôi biết trạng thái.

0

Tôi gặp sự cố tương tự với quảng cáo gốc Admob. Tôi muốn đặt quảng cáo trong chế độ xem của người tái chế. Cuộn qua, giao diện người dùng sẽ đóng băng khi tôi nhấn quảng cáo gốc và cuộn sẽ chỉ tiếp tục khi quảng cáo đã tải

Tôi đã thực hiện một số thời gian và thấy rằng loadAd() sẽ mất khoảng 1400ms, các cuộc gọi tiếp theo để loadAd() đã giảm xuống 150ms, do đó, bản sửa lỗi của tôi là tạo quảng cáo gốc ngay sau khi đoạn của tôi đã được tạo:

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; 
} 
Các vấn đề liên quan