比旧的操作系统版本不同绘制的Andr​​oid 4.2 9补丁背景 [英] Android 4.2 9-patch background drawn differently than older OS versions

查看:173
本文介绍了比旧的操作系统版本不同绘制的Andr​​oid 4.2 9补丁背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的Nexus 7与Android 4.2.1,我在我的应用程序注意到我使用一些线性布局的背景图像被错误地绘制。随着与旧版本的Andr​​oid的其他设备OS 9补丁背景正确,但绘制该设备时,它不应该被拉伸的边界线拉长。

校正(EVO 4G V2.3.5):
http://i.imgur.com/WDTNr.png

不正确(N7 V4.2.1):
http://i.imgur.com/HntMY.png

任何想法是什么原因造成的?如果没有,是否有任何其他方式来获得对这些观点的黑色边框不使用9片图像?

修改

9补丁文件:
http://i.imgur.com/LDoBE.png

9补丁编辑工具:
http://i.imgur.com/UoydG.png

使用它(leftbordergraybkg)布局XML部分:

 <的LinearLayout
 机器人:ID =@ + ID /测量
 机器人:layout_width =0像素
 机器人:layout_height =match_parent
 机器人:layout_weight =50
 机器人:背景=@绘制/ leftbordergraybkg
 机器人:方向=垂直>


解决方案

这是因为黑色像素显示可扩展区域过于靠近图像的边框。这就是为什么在高像素密度的9补丁文件扩展和横向扩展一块边界的。

请参阅例子不会有这样的问题。

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

解决方案

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.

这篇关于比旧的操作系统版本不同绘制的Andr​​oid 4.2 9补丁背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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