背景图像会导致第二线性布局消失
问题描述:
我有一个布局,看起来像这样背景图像会导致第二线性布局消失
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
style="@style/Splash">
<TextView android:id="@+id/splash_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Splash.H1"
android:text="@string/splash_title"/>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/splash_image"
android:src="@drawable/ic_launcher_ftnicon"
style="@style/Splash.Image"/>
<TextView android:id="@+id/splash_powered_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Splash.H2"
android:text="@string/splash_powered_by"/>
</LinearLayout>
</LinearLayout>
我的风格是这样的
<style name="Splash">
<item name="android:gravity">center</item>
<item name="android:background">#FFFFFF</item>
</style>
当我改变的背景下被拉伸,就像这样:
<style name="Splash">
<item name="android:gravity">center</item>
<item name="android:background">@drawable/bg_splash</item>
</style>
第二个线性布局完全消失。背景图片显示并显示标题的文本视图。
答
这是我认为正在发生的事情。
Your @ drawable/bg_splash是一个全屏图像。
请记住,对于样式,所有孩子都将继承父级的设置(即Splash.H1也将具有与Splash相同的背景)。这意味着所有视图的背景将被设置为相同的全屏图像。按照您定义的方式进行布局,唯一显示的视图是“@ + id/splash_title”文本视图。线性布局将被强制离开屏幕底部。
是否有助于记住,如果将背景图像设置为包装其内容的视图,其最小尺寸将是背景图像的最小尺寸? – bigstones 2011-04-15 19:46:23
我不认为这真的对此产生影响,因为所讨论的文本都使用中心重力。根linearlayout内部的文本应该在中间,但其他线性布局甚至没有显示。 – Josh 2011-04-15 19:48:24
您是否尝试过使用Hierarchy Viewer查看内部布局会发生什么? – bigstones 2011-04-15 20:04:57