问题
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