java - AdMob 横幅太小

标签 java android admob

enter image description here我有一个 AdMob 横幅,它可以正确显示,但它太小了。它不适合屏幕的宽度。这在模拟器和真实设备上都会发生。谁能帮我解决这个问题? XML代码:

  <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/LinearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/usernameLab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username:"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="35px" />

    <EditText
        android:id="@+id/usernameField"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName" />

    <TextView
        android:id="@+id/passwordLab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Password:"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="35px" />

    <EditText
        android:id="@+id/passwordField"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/login"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Login" />

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Remember me?" />

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Parent Account?" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="124dp"
        android:src="@drawable/cool" />

    <LinearLayout
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="..."
            ads:loadAdOnCreate="true"
            />
    </LinearLayout>
</LinearLayout>

最佳答案

根据您发布的图片,广告以 320 x 50 像素显示,整体分辨率为 480 x 800。我假设像素密度为 1.0(这将是 160 的抽象 LCD 密度, AVD 设备属性下的设置)。这是一个不寻常的密度。绝大多数手机的像素密度为 1.5(抽象 LCD 密度为 240),导致屏幕宽度为 320 dip,使用该设置应该可以正确渲染。

如果您想确保您的广告始终充满屏幕宽度,有两种方法。在 Honeycomb 及更高版本(API 级别 11+)上,您可以使用 setScaleX() 和 setScaleY() 对其进行缩放。您必须获得屏幕宽度并适本地缩放它。对于 Gingerbread 和更早的版本,您必须计算缩放比例。我不知道那里有哪些选项。缩放会导致一些像素化,通常人们更喜欢将广告居中而不是拉伸(stretch)它。

TL;DR:大多数人会看到它很好,您可以将它居中或自己拉伸(stretch)

关于java - AdMob 横幅太小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8598911/

相关文章:

android - 嵌套 LinearLayout 中不遵守重量比例

android - ContentResolver 在 API 级别 18 上抛出 FileNotFoundException

android - Admob 原生广告中的可点击区域

android - Admob,填充率真的很差

在 SpriteKit 中使用 Swift 的 IOS admob

java - 如何将改造的回调从 Activity 移动到类

java - 为什么不赞成在 Swing 中使用空布局?

java - 为单个 JTree 定制 Tree.collapsedIcon

java - LIBGDX 不断向终端打印 "DefaultShaderProvider: Creating new shader"

android - 如何在不保存到设备的情况下在 ImageView 中加载 Cipher 加密的图像文件