简体   繁体   中英

Nine Patch Drawable Being Clipped

I'm at a bit of a loss with this one, I have a nine patch drawable (See attached) which works in the draw9Patch tool, has no bad patches, works fine on initial loading of the application for ldpi, mdpi, hdpi 1.6 - 2.3.3.

But on each screen size if I go to another activity and then back to the original screen containing the button with the nine patch drawable as it's background, the image is cropped at the top (looks as though it's occurring at the repeatable area).

I've gone through the layout an altered any nine patch drawable used to ensure it's not one rogue nine patch causing the issue with the rest. I've ensured that each density pixel screen has it's own set of resources and I'm about to try moving the xml state selectors for the button into each of the respective drawable folders as well.

The frustrating thing is that even if the nine patches draw incorrectly, rotating the screen seems to fix the problem, it's only when I move from a new activity back to the problem activity, the nine patches clip 50% of the time.

The Drawable is:

问题九补丁

The left portion of the resulting image is as follows (Notice there is no rounded edge):

渲染问题九补丁

If you actually zoom in on the rendered image, it appears to have the top of the nine patch (above the scaled pixel) overlapping the drawable underneath (zoom in and you see the round corner).

The layout for the button has nothing unusual about it:

<Button
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:text="@string/some_text"></Button>

I can set the layout_height to a fixed height (ie 50dp) and this seems to stop the nine patch collapsing on itself / clipping.

If anyone has any ideas at all as to what the problem could be please let me know.

Cheers, Matt

Solution:

My problem was to do with the following boolean parameters in the state list selector:

android:constantSize="true" android:dither="false" android:variablePadding="false"

I'm not sure what caused the behaviour, but I assume it causes some form of caching or some optimisation that introduced this intermittent bug.

My problem was to do with the following boolean parameters in the state list selector:

android:constantSize="true" 
android:dither="false" 
android:variablePadding="false"

I'm not sure what caused the behaviour, but I assume it causes some form of caching or some optimisation that introduced this intermittent bug.

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