android - Admob 横幅不在屏幕底部

标签 android admob

我为 Admob 编写了代码。这是我的layout.xml文件代码:

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

输出:

Screen shot

我的activity.java代码:

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();
}
}

我想要屏幕底部顶部的栏(是的,那个黑色栏)。我也为它写过,但它显示的输出如上图所示。

而且我不明白哪一个是 admob 横幅,顶部的还是底部的??谁能解释一下这两个酒吧的区别。其实我对此很陌生。这是我第一次为 admob 编写代码。请帮助我学习这一点。

最佳答案

两者都是admob 横幅。如果您希望在底部展示广告,请从 Activity 中删除以下代码,因为您已经在底部的 xml 中添加了代码。

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

关于android - Admob 横幅不在屏幕底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15151893/

相关文章:

android - 用 RxJava 替换监听器

android - 在 Google Play 应用内结算中消费已取消的购买

android - 迁移到 Androidx 后 SwitchCompat 为白色

安卓工作室 : Unable to start the daemon process

ios - AdMob 中介与 iAd

android - Activity 首次启动时无法开始创建弹出窗口

java - 应用内结算广告移除 : Ads are not showing

java - 在类(class)中添加广告 Admob 并从另一个 Activity/类(class)调用

Android:Millennial Media 的 AdMob 中介在发布 APK 中不起作用

ios - ios中的cordova 'admob free'-应用程序运行时出现异常