Android 4.2 9-patch background drawn differently than older OS versions

帅比萌擦擦* 提交于 2019-12-23 03:21:30

问题


I have a Nexus 7 with Android 4.2.1 and I noticed in my app the background image I am using for some linear layouts is drawn incorrectly. With other devices with older versions of the Android OS the 9-patch background is drawn correctly but with this device the border line is stretched when it should not be stretched.

Correct (Evo 4G v2.3.5): http://i.imgur.com/WDTNr.png

Incorrect (N7 v4.2.1): http://i.imgur.com/HntMY.png

Any idea what is causing this? If not, is there any other way to get the black borders on these views without using 9-patch images?

edit

9-patch file: http://i.imgur.com/LDoBE.png

9-patch in editor tool: http://i.imgur.com/UoydG.png

layout xml section using it (leftbordergraybkg):

<LinearLayout
 android:id="@+id/Measurements"
 android:layout_width="0px"
 android:layout_height="match_parent"
 android:layout_weight="50"
 android:background="@drawable/leftbordergraybkg"
 android:orientation="vertical">

回答1:


It's because of black pixels showing scalable area are too close to image's border. That's why in higher pixel density 9-patch file scales up and scale piece of border.

See example which will not have such problem.



来源:https://stackoverflow.com/questions/13767012/android-4-2-9-patch-background-drawn-differently-than-older-os-versions

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