简体   繁体   English

我的游戏中没有足够的空间来展示广告

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

My MainActivity java Is a simple game but the admod dont show 我的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;
    }

}

I Dont know why but my activity_main.xml dont show admob.. admob work and the game too but toguether dont work (sorry for my english) 我不知道为什么,但是我的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>

Thank you 谢谢

I think this is way easier: 我认为这更容易:

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

Set it in your xml and it will work. 在您的xml中设置它,它将起作用。

Oh, and dont forget the manifest: 哦,别忘了清单:

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

I think that is only for interstitials but just in case add it 我认为这仅适用于非页内广告,以防万一添加

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM