2017-02-19 119 views
1

我最近开始在我的android应用中使用admob横幅广告。它工作得很好,但我有一些问题。至于现在,我使用的是BANNER,而不是SMART_BANNER。我的广告在大多数手机上都可以使用,除了一个小组。在我的模拟器上,当横幅对于屏幕太大时,我可以看到问题发生。在Android工作室调整admob横幅到屏幕大小

我试过使用智能横幅,但我仍然在logcat中得到相同的消息:“横幅需要340x50,只有288x460”。我的横幅广告在大多数5英寸屏幕上都有效,但是当我在较小的屏幕尺寸上试用这款应用程序时,横幅不可见。

所以我的问题是:如何调整横幅以适应所有屏幕?大小

这里是我的代码,我用它来创建广告横幅:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" android:layout_height="match_parent"> 

    <android.support.percent.PercentRelativeLayout 

     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:id="@+id/timer1background2" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="127dp" 
      android:id="@+id/TimerTextview1" 
      android:textColor="@android:color/black" 
      android:textStyle="normal|bold" 
      app:layout_marginTopPercent="11%" 
      android:text="APP NAME" 
      android:textSize="45dp" /> 

     <Button 
      android:text="Go To Timer 1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:id="@+id/StartB1" 
      android:textColor="@android:color/background_light" 
      android:background="@color/colorPrimaryDark" 
      android:textStyle="normal|bold" 
      android:textSize="35sp" 
      app:layout_marginTopPercent="33%" 
      app:layout_heightPercent="15%"/> 

     <Button 
      android:text="Go To Timer 2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:id="@+id/StartB2" 
      android:textColor="@android:color/background_light" 
      android:background="@color/colorPrimaryDark" 
      android:textStyle="normal|bold" 
      android:textSize="35sp" 
      app:layout_marginTopPercent="58%" 
      app:layout_heightPercent="15%"/> 

    </android.support.percent.PercentRelativeLayout> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="MY KEY"> 
    </com.google.android.gms.ads.AdView> 
</RelativeLayout> 

和:

//Load ads 
MobileAds.initialize(getActivity().getApplicationContext(), "MY KEY"); 

AdView adView = (AdView) myView.findViewById(R.id.adView); 
AdRequest adRequest = new AdRequest.Builder().build(); 
adView.loadAd(adRequest); 

回答

0

从谷歌文档的广告,横幅广告来在特定大小,see here,对于全屏广告,我认为您应该为它使用插页式广告。 Documented here。进来固定大小

+0

你可以看到,最小宽x高BANNER是320x50。那么如果屏幕尺寸比那个小? – AndreasWT

+0

那就是比率。如果设备宽度发生变化,则广告视图会调整它。 – ADM

+0

但是当我像你说的那样做时,广告就不会显示。只有当屏幕有空间时才可以。 – AndreasWT

0

常规横幅广告,你需要什么,你不能扩展它们

是智能横幅填补了屏幕的宽度

this