9补丁可绘制尺寸的Andr​​oid。如何不同密度处理非拉伸区域? [英] 9-Patch drawable dimensions Android. How do different densities handle the non-stretched areas?

查看:649
本文介绍了9补丁可绘制尺寸的Andr​​oid。如何不同密度处理非拉伸区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑上面的图片。 - 虚线划定的9补丁PNG我会切出的Photoshop文件。我需要它来创建一个弹出框。 - 这个盒子采用了阴影效果如图这张照片的测量工具。 - 粉红色的线在那里展示如何我会用draw9Patch工具创建9个补丁

Consider the above image. - The dotted line demarcates the 9-Patch png I will slice out of a photoshop file. I need it to create a popup box. - The box incorporates a dropShadow as shown by the measuring tool in this photo. - The pink lines are there to show how I will use the draw9Patch tool to create the 9-Patch.

我的问题是,:如果我有一个观点容器与9补丁背景我需要确保其子的观点始终是内部的白色盒子。我打算用填充了这一点。我要设置填充等于测量工具。所以如果是30PX在Photoshop我就放 layout_paddingLeft= 30dp的容器。 (设计是MDPI,所以我认为这个转换是好的)。但是怎么做不同密度的屏幕处理9path。例如将实测面积是 30像素 30dip

My question is: If I have a View "Container" with the 9-Patch for a background I need to ensure its children views are always inside the white box. I was going to use padding for this. I was going to set the padding to equal the measuring tool. So if it is 30px in photoshop I'll set layout_paddingLeft"=30dp" for the container. (The design is at MDPI so I assume this conversion is okay). However how do screens of different densities handle the 9path. For instance will the measured area be 30px or 30dip ?

推荐答案

通过 draw9patch 工具,您可以定义:

Via the draw9patch tool you can define:

  • 纵向拉伸:黑色像素左侧
  • 横向拉伸:黑色的像素上侧
  • 垂直内容:黑色像素右侧
  • 水平含量:黑色像素底部
  • vertical stretching: the black pixels on the left side
  • horizontal stretching: the black pixels on the top side
  • vertical content: the black pixels on the right side
  • horizontal content: the black pixels on the bottom

请注意,拉伸像素不必是连续的,所以你可以从拉伸排除一些特定的切片(查看弹出箭头以上)。在他同一时间,你可以在哪里你的内容将被放置只是走一下右侧的preVIEW,在紫光地区合理的想法。正如你所想,这样你就不必在布局指定任何填充:视图将使用您设置为背景的9patch考虑到这些值

Note that stretching pixels don't have to be contiguous, so you can exclude some specific slice from stretching (look at the popup arrow above). At he same time you can make a reasonable idea of where your content will be placed just taking a look at the preview on the right, with the violet areas in. As you can suppose, this way you don't have to specify any padding in your layout: the view will take into account those values using the 9patch you set as background.

在没有拉伸的区域​​扩展的像素密度。所以,如果你上面设置为 MDPI 资产,顶最左边的片是在一个50x40像素区域@mdpi呈现的9patch,并在100x80像素面积@xhdpi。最左边的拉伸区域,而不是根据dpi的安排它们的宽度,而高度根据内容排列。其他拉伸片以类似的方式工作。

The no-stretching areas scale with the pixel density. So, if you set the 9patch above as an mdpi asset, the top-leftmost slice is rendered in a 50x40 pixels area @mdpi, and in 100x80 pixels area @xhdpi. The leftmost stretching areas instead arrange their width according to dpi, while height is arranged according to content. Other stretching slices work in similar way.

在这两种情况下,处理一个低分辨率9patch可导致难看的像素化文物。一种可能的解决方案是提供一个不同9patch为每个支持的DPI,或只以限定更高的人(xhdpi),并让机器人规模下来相应

In both cases, dealing with a "low resolution" 9patch can lead to ugly pixelation artifacts. A possible solution is to provide a different 9patch for each supported dpi, or to define only the higher ones (xhdpi) and let Android scale them down accordingly.

内容的界限,如 DP 过处理,所以他们的规模,根据像素密度。例如:在原来的9patch为40PX @ MDPI定义的左填充,将被翻译成80px @ xhdpi,所以内容将不会流出来给定的范围。 注意,你甚至可以ovverride通过填充在9patch指定的内容范围* 属性在布局中。

The content bounds are handled as dp too, so they scale according to pixel density. For example: a left padding defined in the original 9patch as 40px@mdpi, will be translated in 80px@xhdpi, so the content will never flow out the given bounds. Note you can even ovverride the content bounds specified in 9patch via the padding* properties in your layout.

这篇关于9补丁可绘制尺寸的Andr​​oid。如何不同密度处理非拉伸区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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