简体   繁体   中英

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

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:
9补丁图片

Hopefully this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM