簡體   English   中英

我的游戲中沒有足夠的空間來展示廣告

[英]Not enough space to show ad in my game

我的MainActivity java是一個簡單的游戲,但是admod不顯示

public class MainActivity extends Activity {
    private AdView adView;
    private MainView mainView;
    private final int MENU_SELECT_RESET = 1, MENU_SELECT_CONTACT = 2;

    // MUSICA
    MediaPlayer mediaPlayer;// para musica de fondo (se declara aqui para que
                            // pueda

    // utilizarla todos nuestros metodos)

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        // Crear el objeto adView
        adView = new AdView(this, AdSize.BANNER, "a14e2f8fe3af5a6");

        // Buscar LinearLayout suponiendo que se le ha asignado
        // el atributo android:id="@+id/mainLayout"
        LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);

        // Añadirle adView
        layout.addView(adView);

        // Iniciar una solicitud genérica para cargarlo con un anuncio
        adView.loadAd(new AdRequest());




        // MUSIC
        mediaPlayer = MediaPlayer.create(this, R.raw.merry);
        mediaPlayer.setLooping(true);
        mediaPlayer.setVolume(100, 100);
        mediaPlayer.start();


        //MAINVIEW
        // TURN OFF THE TITLE
       // requestWindowFeature(Window.FEATURE_NO_TITLE);
        // Apago la barra de estado
    //   getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        Intent i = getIntent();
        // Activity Quiero solo tapa
     //   i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
        // View Establezca el
       // mainView = new MainView(this);
        //setContentView(mainView);
       RelativeLayout layout1 = (RelativeLayout) findViewById(R.id.mainView); mainView = new MainView(this);
        layout1.addView(mainView);


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        // getMenuInflater().inflate(R.menu.activity_main, menu);
        menu.add(0, MENU_SELECT_RESET, 0, "Reset");
        menu.add(0, MENU_SELECT_CONTACT, 0, "Contact");
        return true;

    }

    @Override
    protected void onResume() {
        mediaPlayer.start();

        // Leí el recuento juego
        this.mainView.gameCount.read();
        Log.d("", "read");
        super.onResume();

    }

    @Override
    protected void onPause() {
        mediaPlayer.pause();

        // Escribo el recuento de juego.
        this.mainView.gameCount.save();
        Log.d("", "save");

        super.onPause();
        // No voy a desaparecer en esta actitud no hay más.
        // finish();

    }

    @Override
    protected void onDestroy() {
        mediaPlayer.stop();

        System.exit(0);

    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case MENU_SELECT_RESET:
            this.mainView.gameCount.reset();
            Toast.makeText(this, "Has been reset.", Toast.LENGTH_SHORT).show();
            return true;
        case MENU_SELECT_CONTACT:
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_SUBJECT, "idea");
            intent.putExtra(Intent.EXTRA_TEXT, "text of email");
            intent.putExtra(Intent.EXTRA_EMAIL,
                    new String[] { " trabajonacho33@gmail.com" });
            startActivity(intent);
        }
        return false;
    }

}

我不知道為什么,但是我的activity_main.xml也不顯示admob .. admob的工作和游戲,但也沒有顯示(對不起,我的英語)

<?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:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:id="@+id/mainLayout"
              >

 <RelativeLayout
        android:id="@+id/mainView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </RelativeLayout>

</LinearLayout>

謝謝

我認為這更容易:

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

在您的xml中設置它,它將起作用。

哦,別忘了清單:

<activity     
    android:name="com.google.ads.AdActivity"
    android:configChanges = "keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

我認為這僅適用於非頁內廣告,以防萬一添加

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM