我将在下面发布代码,我的问题是,在模拟器 (Genymotion Galaxy Nexus 4.2.2) 中,admob 横幅会拉伸(stretch)并填充其父级:
在真实设备 (Galaxy Nexus 4.3) 中,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/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"/>
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-1470640527107044/6766749615"
ads:adSize="SMART_BANNER"/>
</LinearLayout>
这是 Activity 的 onCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_detail);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
Bundle b = getIntent().getExtras();
url = b.getString("url");
myWebView.loadUrl(url);
myWebView.setWebViewClient(new MyWebViewClient());
// Initiate a generic request.
AdRequest adRequest = new AdRequest.Builder().build();
adView = (AdView) findViewById(R.id.adView);
adView.loadAd(adRequest);
}
我做错了什么?我已经检查了很多,但我无法弄清楚...
最佳答案
答案在AdMob website上(关于智能横幅尺寸):
When an image ad won't take up the entire allotted space for the banner, we'll center the image and use a hexagonal textile filler (see image) to fill up the remaining space. Note that AdSense backfill ads will be centered and have "transparent" filler.
第二张图片有 AdSense 广告,因此填充物是透明的。
关于android - Admob 大小未填满父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20837923/