Creating & Using 9-patch images in Android

前端 未结 8 2121
走了就别回头了
走了就别回头了 2020-11-30 00:39

I recently heard about 9-patch images. I know its 9 tiled and is stretchable. I\'d like to know more about it.

  • How can I create a 9-patch image?

    Is th

8条回答
  •  青春惊慌失措
    2020-11-30 01:11

    Most of the examples talk about creating a 9-patch image, but implementation details are usually left at a high level.

    Nick's post above - with the good 9-patch tutorial that provides a working project download file , saved the day.

    Here are the main implementation details that worked for me (once you have a 9-patch image ready to go):

    1. Reference the drawable with the name but don't include .9.png (auto-complete in eclipse will take care of this)

    2. Make sure you only have 1 image under the main /drawable folder (not a version for each dpi folder)

    3. The image must be specified using :background, not :src (this got me stuck for a while)

      android:background="@drawable/splash_logo"

    4. Make sure the image and layout that contains it are using:

      android:layout_width="fill_parent"
      android:layout_height="fill_parent"

提交回复
热议问题