Android XML Layout works in landscape but not in normal orientation

不羁的心 提交于 2019-12-11 01:45:58

问题


I'm trying to display an Admob ad but this only works in Landscape but not in normal mode.

layout-land/main.xml and layout/main.xml are the same! (well now they are because i deleted everything else to find the bug)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res/test.testpkg"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:padding = "10dip" >

        <com.admob.android.ads.AdView
            android:id="@+id/ad" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            myapp:backgroundColor="#000000"
            myapp:primaryTextColor="#FFFFFF"
            myapp:secondaryTextColor="#CCCCCC" />

</RelativeLayout>

回答1:


Remove the padding from your Relative Layout. AdMob doesn't play nice when an ancestor View is padded.

 <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/test.testpkg"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    >


 <com.admob.android.ads.AdView
 android:id="@+id/ad" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent"
 myapp:backgroundColor="#000000"
 myapp:primaryTextColor="#FFFFFF"
 myapp:secondaryTextColor="#CCCCCC"
   />
</RelativeLayout>


来源:https://stackoverflow.com/questions/4281349/android-xml-layout-works-in-landscape-but-not-in-normal-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!