【问题标题】:Linear Layout background not shown on Galaxy NexusGalaxy Nexus 上未显示线性布局背景
【发布时间】:2013-10-24 11:20:08
【问题描述】:

我有一个使用列表视图来显示信息的应用程序,并且我已经放置了部分来划分不同类型的数据。这是一个屏幕截图,它在 Android 4.1.2 http://postimg.org/image/ujv765wf1/ 上的外观 它在 Android 4.0.3 上看起来一样,非常完美。

但是在运行 Android 4.3 的 Galaxy Nexus 上,这些部分的背景消失了,看起来像这样http://postimg.org/image/5ik2tayip/

图标和其他可绘制资源正确显示,但唯一的背景不是。它们之间的唯一区别是背景是在 XML 文件中声明的,而其他资源是通过编程方式添加的。

这是该部分的 XML 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
    android:background="@drawable/greenstripe">


        <ImageView
        android:id="@+id/sectionIcon"
        android:layout_width="45dip"
        android:layout_height="37dip"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="20dip"
        android:contentDescription="@string/emptyString" />

        <TextView android:id="@+id/textViewProject"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:layout_gravity="center_vertical"
        android:textColor="#FFFFFF"
        android:textSize="23sp" 
         />


</LinearLayout>

我想如果我通过代码添加背景应该可以工作,但我想知道这里有什么问题,为什么在 Android 4.3 上没有显示背景?先感谢您。

编辑:我尝试从 .png 和 .xml 文件中分配背景,但仍然没有显示。另外,我发现目前这个问题只发生在 Galaxy Nexus 上,当我在运行 Android 4.3 的 Galaxy S3 上进行测试时,一切都很好。

编辑2:现在问题自行消失了,如果有什么值得注意的事情发生,我会密切关注并写下

【问题讨论】:

  • 您是否在所有可绘制文件夹中添加了 greenstripe.xml
  • 是的,它就在那里,还有所有其他资源。在我测试过的其他设备上看起来还不错。只有在运行 Android 4.3 的设备上它才会消失
  • 等等!它不是 .xml,而是 .png
  • 无论如何,如果我创建一个 greenstripe.xml 使用它而不是 .png 也没关系,LinearLayout 背景仍然没有出现在 4.3
  • 您是否使用了分辨率非常高的图像?

标签: android android-4.3-jelly-bean xml-layout


【解决方案1】:

我也有同样的问题:

  • 一个白色背景的 ListView
  • 每个孩子都有一个灰色背景的视图,宽度和高度与相对布局中的 match_parent 相匹配

在 API 17 上,一切正常

在 API 18+ 上,ListView 是白色的

我没有设置固定的高度,而是在视图中放了一个 min_height,问题(暂时)解决了!

希望对你有帮助

【讨论】:

  • 问题是我根本没有使用固定高度,我在布局和视图中都使用了 wrap_content
  • 我也没有。只需添加一个 min_height 属性就可以了(我不知道为什么,显然这是 API 18+ 中的一个错误)
【解决方案2】:

我认为这是您观点的回收问题。您需要在适配器的 getView() 方法中重置背景。如果您需要更多帮助,请复制/粘贴您的适配器代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多