Utility of android nine patch

后端 未结 8 1375
鱼传尺愫
鱼传尺愫 2020-12-06 07:57

I would like to know why do we use nine-patch ? I know is to shrink or stretch images but if I want to resize an image can\'t we just do it on a dedicated image editor like

相关标签:
8条回答
  • 2020-12-06 08:31

    The advantage of using 9-patch images is that when using it as a background, for instance, the image won't stretch and loose proportions in different screen sizes. the center 'patch' will remain as is and the 'borders' patches will be stretched to fit the screen/view size.

    one more and biggest advantage is memory. Same small size memory can be reused for different screen size devices.Well-designed 9-patch images are less error-prone and have high reusability. I had hard time optimizing the UI for different resolutions until I knew that Android supports 9-patch.

    For padding as @hotveryspicy said you can use the padding box ( where your text button will be filled) to define your paddig values and they are defined like this:

    1. padding-top: distance between the top edge of the padding box and the top edge of your button
    2. padding-bottom: distance between the buttom edge of the padding box and the buttom edge of your button
    3. padding-right: distance between the right edge of the padding box and the right edge of your button
    4. padding-left: distance between the left edge of the padding box and the left edge of your button

    Hope this will help you to have a clear idea and how important 9-patch drawable are

    0 讨论(0)
  • 2020-12-06 08:33

    Nine-patch allow you to strech just a part of an image, and not the whole image. It can be useful to design for example custom buttons, EditTexts, etc...

    You can lean more here: http://developer.android.com/tools/help/draw9patch.html

    0 讨论(0)
提交回复
热议问题