Android Fragments API doesn't show background 9patch image correctly

梦想与她 提交于 2019-12-11 03:37:20

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/6447318/android-fragments-api-doesnt-show-background-9patch-image-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!