android - 背景图像导致第二个线性布局消失

标签 android android-layout

我有一个看起来像这样的布局

<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/

相关文章:

java - 是否可以扩展 Android Camera 类?

android - 如何获取附近城市的天气预报

javascript - React Native - 传递数据时 setState 未定义

android - Android 支持库和 Maven 的 NoClassDefFoundError

android - 背景图片崩溃android

android - 布局权重在 ScrollView 中不起作用

android - 如何将带有圆角的android BottomAppBar

android - 使用在 Android 中使用 Jsoup 解析的 html 内容从 webView 中删除链接

带有 2 个图像的 Android 布局在底部留下空白

android - 如何在 Android 的 PopupWindow 中设置 ListView 的宽度?