android - Admob 大小未填满父级

标签 android android-layout admob

我将在下面发布代码,我的问题是,在模拟器 (Genymotion Galaxy Nexus 4.2.2) 中,admob 横幅会拉伸(stretch)并填充其父级:

enter image description here

在真实设备 (Galaxy Nexus 4.3) 中,admob 横幅不会填满其父级的整个宽度,在两侧留下两条白色条纹:

enter image description here

这是布局:

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

相关文章:

android - 将我的应用程序连接到 Firebase 时出现问题

android - viewBinding为什么让XML根全屏

android - 在 sharedpreference 中同时使用 apply() 和 commit()

admob - 我需要在生产中删除 adRequest.addTestDevice 吗?

java - 如何使用 Github API 列出所有 Github android 项目?

android - 04-02 15 :03:22. 624:E/Database(390):准备“如果不存在则创建表”时,0x267938 上出现故障 1( "View"附近:语法错误)

android - 如何在App上显示一次启动画面?

java - Admob 原生广告加载失败,错误代码为 0

android - Adwhirl - 千禧年广告 - 不受支持的定量类型

Android Phonegap 版本 2.0 或更高版本 facebook、twitter、消息等共享插件的任何更新