Android的XML布局工作在景观,但不是在正常的方向 [英] Android XML Layout works in landscape but not in normal orientation

查看:152
本文介绍了Android的XML布局工作在景观,但不是在正常的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示 Admob的广告,但它只适用于景观,但不是在正常模式下。

布局陆/ main.xml中布局/ main.xml中都是一样的! (当然现在他们是因为我删除一切去寻找错误的)

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:的myapp =htt​​p://schemas.android.com/apk/res/test.testpkg
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@可绘制/背景
    机器人:填充=10dip>

        < com.admob.android.ads.AdView
            机器人:ID =@ + ID /广告
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
            的myapp:的backgroundColor =#000000
            的myapp:primaryTextColor =#FFFFFF
            的myapp:secondaryTextColor =#CCCCCC/>

< / RelativeLayout的>
 

解决方案

从相对布局中取出的填充。 AdMob的没有发挥好当的祖先视图被填充。

 < RelativeLayout的
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:的myapp =htt​​p://schemas.android.com/apk/res/test.testpkg
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@可绘制/背景
    >


 < com.admob.android.ads.AdView
 机器人:ID =@ + ID /广告
 机器人:layout_width =FILL_PARENT
 机器人:layout_height =FILL_PARENT
 的myapp:的backgroundColor =#000000
 的myapp:primaryTextColor =#FFFFFF
 的myapp:secondaryTextColor =#CCCCCC
   />
< / RelativeLayout的>
 

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>

解决方案

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>

这篇关于Android的XML布局工作在景观,但不是在正常的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆