2011-12-22 137 views
1

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

<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> 
+0

您使用的是什么分辨率和密度?你可以张贴截图吗? – Hounshell 2011-12-22 10:04:47

+0

您的adview宽度为'wrap_content',设置为'android:layout_width =“match_parent”' – Jakar 2011-12-22 10:18:40

+0

我上传了一张图片以向您展示。 @贾卡尔,我试着改变你的建议,这是不行的。它可能是我使用ViewSwitcher的东西吗?谢谢。 – Eli 2011-12-22 13:34:36

回答

1

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

如果您想确保您的广告始终充满屏幕宽度,有两种方法。在Honeycomb及更高版本(API Level 11+)上,您可以使用setScaleX()和setScaleY()对其进行缩放。您必须获取屏幕宽度并适当缩放。对于姜饼和更早的你必须弄清楚缩放。我不知道那里有什么选择。缩放会导致一些像素化,并且通常人们更喜欢将广告居中而不是拉伸它。

TL; DR:大多数人会看到它很好,你可以居中或自己舒展它