0

我在我的应用程序中添加了 Adsense。问题是我只看到没有活动原始内容的广告。可能是什么原因?

这是活动:

包 com.example.newpingpong;

import com.google.ads.*;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;


import android.os.Bundle;

import android.preference.PreferenceManager;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v4.app.NavUtils;
import android.view.View;

public class Grid extends Activity {

    private AdView adView;
    public Intent intent;


    SharedPreferences preferences;
    int level_int;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grid);

        //for ad: + manifest + above import and change in properties+lib +java class or in the layout
        // Look up the AdView as a resource and load a request.
        AdView adView = (AdView)this.findViewById(R.id.adView);
        adView.loadAd(new AdRequest());

        Const.isLevelEVERCompleted = new boolean[Const.LevelsAmount];
        for(int i=0 ; i< Const.LevelsAmount ; i++){
            Const.isLevelEVERCompleted[i] = false;
        }

    }


    @Override
    public void onResume()
    {
        preferences=PreferenceManager.getDefaultSharedPreferences(this);

         Const.isAllLevelsComplete = true;
        for(int i=0 ; i< Const.LevelsAmount ; i++){
            //int j=i+1;
            if(preferences.getInt("level"+i, Const.NOT_STARTED) == Const.NOT_STARTED){
                Const.isLevelEVERCompleted[i] = false;
                Const.isAllLevelsComplete = false;
            }
            else
                Const.isLevelEVERCompleted[i] = true;
        }

        TextView editText3 = (TextView) findViewById(R.id.win);
        if( Const.isAllLevelsComplete == true)
            editText3.setText("WIN!");
        else
            editText3.setText("");


        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));


        gridview.setOnItemClickListener(new GridView.OnItemClickListener() 
        {
            public void onItemClick(AdapterView parent, View v, int position, long id) 
            {                


            }
        });

        super.onResume();       
    }



    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}

这是布局

<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout_delek"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/aliceblue"
    android:layout_gravity="right" >


    <com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
ads:adSize="BANNER"
ads:adUnitId="a1524d50e6097be"
/>

    <TextView
        android:fontFamily="monospace"
        android:freezesText="true"
        android:text= "@string/app_name"
        android:textSize="35sp"
         android:gravity="center"
        android:textColor="#800000"
          android:paddingTop="15dp"
        android:paddingBottom="20dp"
        android:textStyle="bold" />

        <TextView
            android:id="@+id/win"
        android:fontFamily="monospace"
        android:freezesText="true"
        android:text= ""
        android:textSize="35sp"
         android:gravity="center"
        android:textColor="#600000"
          android:paddingTop="15dp"
        android:paddingBottom="20dp"
        android:textStyle="bold" />



    <GridView
        android:id="@+id/gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:columnWidth="90dp"
        android:gravity="center"
        android:horizontalSpacing="10dp"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth"
        android:background="@color/aliceblue"
        android:verticalSpacing="10dp" />

    <TableRow
        android:id="@+id/tableRow1_delek1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="14.5sp"
        android:layout_marginTop="20sp"
        android:gravity="center"
        android:padding="5dip" >
    </TableRow>

</TableLayout>
4

1 回答 1

0

尝试这个..

因为 admob hightandroid:layout_height="fill_parent"它将填充父级以便它发生

<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout_delek"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/aliceblue"
    android:layout_gravity="right" >


    <com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"        //correction here
ads:adSize="BANNER"
ads:adUnitId="a1524d50e6097be"
/>

    <TextView
        android:fontFamily="monospace"
        android:freezesText="true"
        android:text= "@string/app_name"
        android:textSize="35sp"
         android:gravity="center"
        android:textColor="#800000"
          android:paddingTop="15dp"
        android:paddingBottom="20dp"
        android:textStyle="bold" />

        <TextView
            android:id="@+id/win"
        android:fontFamily="monospace"
        android:freezesText="true"
        android:text= ""
        android:textSize="35sp"
         android:gravity="center"
        android:textColor="#600000"
          android:paddingTop="15dp"
        android:paddingBottom="20dp"
        android:textStyle="bold" />



    <GridView
        android:id="@+id/gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:columnWidth="90dp"
        android:gravity="center"
        android:horizontalSpacing="10dp"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth"
        android:background="@color/aliceblue"
        android:verticalSpacing="10dp" />

    <TableRow
        android:id="@+id/tableRow1_delek1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="14.5sp"
        android:layout_marginTop="20sp"
        android:gravity="center"
        android:padding="5dip" >
    </TableRow>

</TableLayout>
于 2013-10-03T11:38:23.107 回答