Android Fragments API 无法正确显示背景 9patch 图像

标签 android android-3.0-honeycomb android-fragments nine-patch

我正在将现有的 Android 应用程序移植到 honeycomb 和 fragments API 和兼容性库。我使用的是相同的布局,但我正在将其加载到一个 fragment 中。背景是一个 9patch 图像,但它现在只覆盖了屏幕的左上四分之一。其余的背景是白色的。如果我将背景更改为十六进制颜色,它会覆盖整个屏幕。这在切换到 fragment 之前从未发生过,布局也没有改变。我对 Android 有点陌生,对 fragment 也很陌生,所以我不确定我是否遗漏了什么。问题似乎与 9patch 图像有关,但我对 Android 的了解还不足以肯定地说。

我的布局是这样的:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/splash_background">

最佳答案

我发现有帮助的是重新制作您的 9patch 图像。它们具有由您指定为非内容区域的部分定义的填充区域。
我发现解决方案是确保 content 区域在整个图像中定义,并确保 stretchable 区域为图像的大部分定义 - 特别是如果您与您的屏幕相比, 9-patch 图像较大。
请参见下面的 9 补丁图像。内容区域以红色突出显示:
9patch image

希望这对您有所帮助。

关于Android Fragments API 无法正确显示背景 9patch 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6447318/

相关文章:

Android:数据变化时如何接收Content Provider的回调?

android - Honeycomb dim status bar + list 中的 minSdkVersion < 11

android - Camera Image Capture Intent 无法在 Galaxy Tab 限量版中返回

android - 如何通过电子邮件发送 webview 内容正文?

当我重新输入 fragment 时,Android MutableLiveData 不断发出信号

android - 尝试使用 -pg [Termux] 时出现 "Undefined reference to ` mcount '"

android - 无法在 Android 上使用 Perl 脚本创建文件(使用 perl-android-apk)

android - 在 Android 中获取用户输入的最快方法

android - 如何在每次应用程序启动时执行一次?

android - android中的Mapapi v2导致 fragment 错误