的AdMob横幅而不是在屏幕的底部 [英] Admob banner not at the bottom of the screen

查看:645
本文介绍了的AdMob横幅而不是在屏幕的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了code适用于AdMob。这是我layout.xml文件code:

I wrote code for Admob. This is my layout.xml file code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:id="@+id/relativeLayoutHomeParent"
tools:context=".Home" xmlns:app="http://schemas.android.com/apk/lib/com.google.ads">

<RelativeLayout
    android:id="@+id/relativeLayoutHomeTopBar"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >

    <TextView
        android:id="@+id/textView1"
        android:text="Home"
        style="@style/screen_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/imageViewHomeSettings"
        android:layout_width="22dp"
        android:layout_height="22dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/set_settings"
        android:layout_marginRight="10dp" />

</RelativeLayout>

<View
    android:id="@+id/view1"
    android:layout_width="match_parent"
    android:layout_height="5dp"
    android:layout_below="@+id/relativeLayoutHomeTopBar"
    android:background="@drawable/shadow" />

<ListView
    android:id="@+id/listViewHome"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="#BDBDBD"
    android:dividerHeight="1dp"
    android:layout_below="@+id/view1" >
</ListView>

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    app:adSize="BANNER"
    app:adUnitId="a1512f50d8c3692"
    app:loadAdOnCreate="true"
    app:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" >
</com.google.ads.AdView>

输出:

我activity.java code:

my activity.java code:

package com.walletapp;

import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.AlertDialog.Builder;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
 import android.database.sqlite.SQLiteDatabase;
 import android.os.Bundle;
 import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
   import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

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

public class Home extends Activity
{
ListView listview_home;
ImageView imageview_settings;
SQLiteDatabase database;
String database_name = "WalletAppDatabase";
private AdView adView;

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

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    imageview_settings = (ImageView) findViewById(R.id.imageViewHomeSettings);
    imageview_settings.setClickable(true);
    imageview_settings.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v)
        {               
            startActivity(new Intent(Home.this, Settings.class));
        }
    });

    String[] home_items = new String[] {"All", "Categories", "Tags", "Favourites"};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.single_row_home, R.id.textViewSingleRowHome, home_items);
    listview_home = (ListView) findViewById(R.id.listViewHome);
    listview_home.setAdapter(adapter);
    listview_home.setOnItemClickListener(new OnItemClickListener()
                                        {
                                            @Override
                                            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
                                            {
                                                String selected = ((TextView) arg1.findViewById(R.id.textViewSingleRowHome)).getText().toString();

                                                switch(arg2)
                                                {
                                                    case 0:

                                                        Toast.makeText(getBaseContext(), "Yet to be code for "+selected, Toast.LENGTH_SHORT).show();
                                                        break;

                                                    case 1:

                                                        Toast.makeText(getBaseContext(), "Yet to be code for "+selected, Toast.LENGTH_SHORT).show();
                                                        break;

                                                    case 2:

                                                        Toast.makeText(getBaseContext(), "Yet to be code for "+selected, Toast.LENGTH_SHORT).show();
                                                        break;

                                                    case 3:

                                                        Toast.makeText(getBaseContext(), "Yet to be code for "+selected, Toast.LENGTH_SHORT).show();
                                                        break;
                                                }
                                            }
                                        }
                                    );

    adView = new AdView(this, AdSize.BANNER, "a1512f50d8c3692");
    RelativeLayout layout = (RelativeLayout)findViewById(R.id.relativeLayoutHomeParent);
    layout.addView(adView);
    adView.loadAd(new AdRequest());
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
    {
        showQuitDialog();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

private void showQuitDialog()
{
    AlertDialog.Builder adb = new Builder(this);
    adb.setTitle("Warning !!!");
    adb.setMessage("Are you sure you want to quit ?");
    adb.setIcon(R.drawable.ic_launcher);
    adb.setPositiveButton("Yes",new DialogInterface.OnClickListener()
                                    {
                                        public void onClick(DialogInterface arg0, int arg1)
                                        {
                                            if(database.isOpen())
                                                database.close();
                                            finish();
                                        }
                                    }
                        );

    adb.setNegativeButton("No",new DialogInterface.OnClickListener()
                                    {
                                        public void onClick(DialogInterface arg0, int arg1)
                                        {
                                            arg0.dismiss();
                                        }
                                    }
                            );
    AlertDialog ad = adb.create();
    ad.show();
}

@Override
public void onDestroy()
{
    if (adView != null)
    {
        adView.destroy();
    }
    super.onDestroy();
}
}

我想这是在顶部(是的黑条),在屏幕底部的工具栏。我也写了,但它显示了输出上面的图片。

I want the bar that is on the top(yes that black bar), on the bottom of the screen. I also wrote for it but it showed the output as the above image.

另外我不明白,哪一个是AdMob的旗帜,最上面的一个或一个底部?任何人都可以解释的区别这两个酒吧。其实我是新来这一点。这是我第一次code代表的AdMob。请帮我了解这一点。

Also i dont understand that which one is the admob banner, the top one or the bottom one ?? Can anyone please explain the difference these two bars. Actually i am new to this. This is the first time i've code for admob. Please help me to learn on this.

推荐答案

只是删除​​这样的:

adView = new AdView(this, AdSize.BANNER, "a1512f50d8c3692");
RelativeLayout layout = (RelativeLayout)findViewById(R.id.relativeLayoutHomeParent);
layout.addView(adView);
adView.loadAd(new AdRequest());

您已经有一个AD浏览你的XML布局。

You already have an adView in your xml layout.

相反,这样做:

adView = (AdView) findViewById(R.id.adView);
adView.loadAd(new AdRequest());

不过,您可能希望加载广告前编辑AdRequest中。这实际上是可选的,你的,但你的收入,如果你这样做会(据说)增加。

However, you might want to edit that AdRequest before loading the ad. That's actually optional and up to you, but your revenue will (supposedly) increase if you do it.

和请,之前的复制粘贴code在SO,首先进行格式化。在Eclipse中,你只需要preSS 按Ctrl + Shift + F

And, please, before copy-pasting code in SO, format it first. In Eclipse you just have to press Ctrl + Shift + F

这篇关于的AdMob横幅而不是在屏幕的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆