5

Java コードから入力された動的テーブルに広告が入力されるアクティビティがあります。このテーブルには、ネットワークから非同期的に読み込まれる画像があります。広告を含めない場合、すべてが期待どおりに機能します。しかし、adview とネットワークから非同期に読み込まれる画像を含めると、画像がネットワークから読み込まれるまで UI がハングします。

動作を理解できませんでした。画像が 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>

ありがとう

アマンディープ

4

2 に答える 2

1

ネットワーク(非同期)アクティビティが実行される Linear Layout 内に adView をロードするのではなく、メインの LinearLayout から 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>

状況を教えてください。

于 2013-09-19T05:25:04.027 に答える
0

Admob ネイティブ広告でも同様の問題がありました。リサイクラー ビューに広告を掲載したいと考えていました。スクロールすると、ネイティブ広告にヒットすると UI がフリーズし、広告が読み込まれるまでスクロールが続行されませんでした。

いくつかのタイミングを行ったところ、loadAd() に約 1400 ミリ秒かかり、その後の 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;
}
于 2016-09-19T10:54:04.607 に答える