Android的碎片API没有正确显示背景图片9patch [英] Android Fragments API doesn't show background 9patch image correctly

查看:137
本文介绍了Android的碎片API没有正确显示背景图片9patch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植现有的Andr​​oid应用程序,以蜂窝碎片API和兼容性库。我使用的是相同的布局,但我加载到一个片段。背景是一个9patch图像,但现在只覆盖屏幕的左上方四分之一。背景的其余部分是白色。如果我改变背景为十六进制的颜色,它覆盖了整个屏幕。此切换到片段之前从未发生和布局没有变化。我有点新的Andr​​oid和很新的片段,所以我不知道如果我失去了一些东西。这个问题似乎涉及到9patch形象,但我不知道有足够的了解Android的说,肯定。

我的布局是这样的:

 <的LinearLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@绘制/ splash_background>


解决方案

这是我发现可以帮助是重新做你的9patch图像的东西。他们必须由您指定为非内容区域的部分定义填充的区域。结果
我找到了解决方法是确保的内容的区域在整个图像定义,以确保的拉伸的面积为它的大部分定义 - 特别是如果你用你的屏幕比较了9片图像大。结果
请参阅下面的9片图像。内容区域以红色突出显示:结果

希望这有助于。

I'm porting an existing android app to honeycomb and the fragments API and compatibility library. I'm using the same layout, but I'm loading it into a fragment. The background is a 9patch image, but it now only covers the top left quarter of the screen. The rest of the background is white. If I change the background to a hex color, it covers the entire screen. This has never happened before switching to fragments and the layout did not change. I'm somewhat new to Android and very new to fragments, so I'm not sure if I'm missing something. The problem appears to be related to the 9patch image, but I don't know enough about Android to say that with certainty.

My layout looks like this:

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

解决方案

Something that I've found helps is to re-do your 9patch images. They have areas of padding defined by the parts that you have designated as non-content areas.
I found the solution was to make sure the content area is defined across the whole image, and to make sure the stretchable area is defined for large portions of it - especially if your nine patch image is large compared with your screen.
See the 9 patch image below. The content areas are highlighted in red:

Hopefully this helps.

这篇关于Android的碎片API没有正确显示背景图片9patch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆