我有一个看起来像这样的布局
<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>
第二个线性布局完全消失。显示背景图像并显示标题的 TextView 。
最佳答案
这是我认为正在发生的事情。
您的@drawable/bg_splash 是全屏图像。
请记住,对于样式,所有子项都将继承父项的设置(即 Splash.H1 也将具有与 Splash 相同的背景)。这意味着所有 View 的背景都将设置为相同的全屏图像。使用您定义布局的方式,将显示的唯一 View 是“@+id/splash_title” TextView 。线性布局将被迫离开屏幕到底部。
关于android - 背景图像导致第二个线性布局消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5681506/