我试图在我的应用程序中使用新的google-service-libs设置admob广告 . 在genymotion模拟器广告中,一切看起来都很好 . 但他们不像我的星系王牌gt5830i与Android 2.3.6真正的设备 . 我不知道是什么问题 .
这是一些代码:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/titleBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/title_bar"
android:orientation="horizontal" >
<ImageView
android:id="@+id/iconImg"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_margin="5dip"
android:background="@drawable/app_icon" />
<ImageView
android:id="@+id/titleImg"
android:layout_width="160dp"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_margin="5dip"
android:background="@drawable/title" />
<RelativeLayout
android:id="@+id/pagerBtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingRight="2dip" >
<ImageButton
android:id="@+id/pager"
android:layout_width="45dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/button_clicked"
android:scaleType="fitXY"
android:src="@drawable/pager" />
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="5dip"
android:background="@drawable/shadow" >
</View>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
ads:adSize="BANNER"
ads:adUnitId="@string/adUnitId" />
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/buttons"
android:divider="#351802"
android:dividerHeight="2dp"
android:listSelector="@drawable/list_selector" />
</LinearLayout>
我的Ad_Unit_Id保存在res /文件夹的string.xml文件中 .
java:
AdView ad = (AdView) findViewById(R.id.adView);
AdRequest req = new AdRequest.Builder().build();
ad.loadAd(req);
如果您需要更多代码,请告诉我 . 谢谢
3 回答
实际上我曾经面对这个问题,因为广告 Banner 需要的分辨率超过了真实手机中的可用空间 .
出于这个原因,一旦你将广告通过此水平测试应用程序..
尝试根据设备的屏幕分辨率动态定义广告
adsize
:它解决了我在其他设备上尝试过它并且工作正常问题是在我的设备和我的朋友设备中因为自定义ROM可能 . 不管怎么说,还是要谢谢你