如果我不在根部布局中包含背景,那么一切都按照我的期望呈现:

Alt Text http://dl.dropbox.com/u/299320/correct.png

但是,如果我只添加一行在背景中添加一行,那么布局就会完全干扰:

Alt Text http://dl.dropbox.com/u/299320/foobared.png

XML布局的相关位是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width ="fill_parent"
    android:layout_height="fill_parent"
    android:paddingRight ="20dip" 
    android:paddingLeft  ="20dip"
    android:gravity      ="center_vertical"
    android:background   ="@drawable/main_background">

从字面上看,上述两个屏幕截图之间的唯一区别是包含 android:background="@drawable/main_background". 。如果您可以在这里帮助我,我会给您一个cookie :)

有帮助吗?

解决方案

至于为什么您在背景中体验自己的状况,可能是您的背景图像以某种方式陷入了重力,但这只是一个猜测。

作为解决方法,将您的整个事情包裹在 FrameLayout. 。成为第一个孩子 FrameLayoutImageView 与您的背景。成为第二个孩子 FrameLayout 成为您的现有 LinearLayout (sans android:background) 属性。自从 FrameLayoutRelativeLayout 允许堆叠,这将导致您的线性层状出现在图像上方,并应为您寻求的视觉效果。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top