2

アプリケーション UI に adView がありますが、表示する広告がない場合は表示したくありません。

アプリケーションに表示する広告があるかどうかを知るにはどうすればよいですか?

これが私のレイアウトです

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res/measurements.areaconvertor"
    android:id="@+id/root_layout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <com.admob.android.ads.AdView
            android:id="@+id/ad"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            myapp:backgroundColor="#000000"
            myapp:primaryTextColor="#FFFFFF"
            myapp:secondaryTextColor="#CCCCCC"/>


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


    <ImageView
                .................
4

2 に答える 2

1

私の経験では、身長に使用するときに広告が存在しない場合、AdViewは自動的に非表示になりますwrap_content

<com.admob.android.ads.AdView
    android:id="@+id/ad"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    myapp:backgroundColor="#000000"
    myapp:primaryTextColor="#FFFFFF"
    myapp:secondaryTextColor="#CCCCCC" />
于 2010-12-11T04:36:27.373 に答える
0

私はこのようにしました

    if(!isOnline()){
       LinearLayout li=(LinearLayout)findViewById(R.id.linearLayourID);
       AdView ad=(AdView)findViewById(R.id.adView);
       ad.setEnabled(false);
       li.setWeightSum(8);
    }


           public boolean isOnline() {
               ConnectivityManager cm =
               (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
               NetworkInfo netInfo = cm.getActiveNetworkInfo();
               if (netInfo != null && netInfo.isConnectedOrConnecting()) {
                    return true;
               }
               return false;
           }
于 2012-04-21T12:48:48.990 に答える