In traditional UI development, if the background size is different, you generally need to create an image for each size, which is particularly evident in the button. Of course, we can also make a small horizontal duplicate, or vertical. In Android, when there is an nine patch image (ending with 9.png) to solve the difference in the background size, only one background image is used.
Use the built-in tools/draw9patch. BAT to open a PNG image. We can draw a black line with pixel width in the outermost space of the PNG image. On the left is the editing area. In the picture on the left, the height of the black line on the left determines the extended area during vertical pull. That is, when vertical stretch is performed, only the image in this area is stretched. Similarly, the black line length on the image determines the extended area when the horizontal pull is performed. The area on the right is vertical, vertical, water, and two directions. This tool provides the WYSIWYG nine patch PNG editing method.
Save the edited PNG as 9.png to the res/drawabledirectory of the project directory. If your 9.png file does not contain a black line, eclipse will report an error.
As follows. We can also understand why nine patch is called. It is equivalent to dividing a PNG image into nine parts, including four corners, four sides, and an intermediate area, the four corners are not raised, so the rounded corners can be maintained. The two flat and vertical edges only stretch horizontally and vertically, therefore, the side will not be grayed out, and only the area specified by the black line is stretched in the middle. The result is that the image is not displayed.
Ninepatch is a "extensible" PNG neural program. Ninepatch example is used to create a picture of "printable text size", for example, interval 1.
Tip 1: The text background can be highlighted in the text size
Ninepatch is a very useful batch chip format. It can be used as the "background batch" of widgets 」. For example, in the example of Example 1, the program design is as follows:
- The text part uses the textview component.
- Use the XML Attribute of textview to set the text size.
- Use the XML Attribute of textview to set a background
- Using ninepatch as the background watermark, the background watermark can be hashed in the text size.
First, the first job is "creating as ninepatch example". The method is as follows.
Step 1. Upload a batch of original PNG images, such as limit 2.
Protocol 2: original png1_png (arrow.png)
Step 2. Activate the draw9patch tool provided by Android, and directly upload the draw9patch line under Android SDK tools/projects, such as example 3.
Release 3: The draw9patch tool provided by the android SDK (Click here to see the original release)
Step 3. Open the original PNG file, such as Example 4.
Release 4: Start your initial failover attempts (Click here to see the original release)
How to publish ninepatch logs
The indexing method of ninepatch logs is "two-condition", and two "black lines" are displayed on the top and left of the original logs 」, the cross-region of the blacklist is the "extensible" region. The following is the pink region of the region.
Option 5: Define extended area
"Extensible area" is the area in which the android framework uses text. In short sentences, text (textview) is only placed in the pink color area, in addition, the original principle is "the central point of the primary region", that is, the upper, lower, and left are also in the middle. Non-"extensible Area", that is, the highlighted area, does not contain the text size. Therefore:
1. The colored area is a fixed area.
2. The pink-colored areas are eXtensible areas and text fields.
How did the "two black lines" appear in the comment? The method is as follows.
Step 4. Adjust the zoom ratio of the mobile device so that the size of the Spotted Horse can be reduced, such as limit 6.
Limit 6: Percentage
Step 7:
Banma County is a region used to create a blacklist. How can this problem be solved? Click the mouse and then click the mouse. How can I remove a hacker? Hold down SHIFT and try again. This is not easy, so if you don't want to intentionally tune your mouse skills and test your eyesight, you can use the zoom function to help the hacker.
Check "show patches" and select "Examples" to show the pink color areas, such as area 7.
7: indicates the Extensible area.
In the right pane of draw9patch, the labels are displayed.
Step 8: ninepatch completed successfully
After the ninepatch logs are saved, draw9patch automatically saves the secondary names of these logs as * .9.png. After ninepatch has been completed, you can start the program.
Start programming: helloninepatch The example of helloninepatch is as follows. Step 1. Create a new Android example named helloninepatch. Step 2. Export arrow.9.png to RES/drawable in helloninepatch cases. For example, lifecycle 1. Release 1: arrow.9.png is added to RES/drawable Resource
Step 3. Modify the UI (RES/layout/Main. XML) and design the faces 2 in the previous tutorial (#30. The content of Main. XML is as follows. <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="small world" android:textSize="12sp" android:background="@drawable/arrow" /><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="big world" android:textSize="24sp" android:background="@drawable/arrow" /><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="super world" android:textSize="48sp" android:background="@drawable/arrow" /></LinearLayout> In this case, place the button component on the UI and set the text and size on the button. According to the preset "Android: background", we set the background of the button to "@ drawable/arrow 」, that is to say, "The drawable data source (the arrowless architecture of the drawable/Project drop-down tables, and the androidframework goes to the arrow.9.png tutorial. Because arrow.9.png is a ninepatch variable, the text size on the button is extended. Step 4: complete hellninepatch You do not need to make any changes to the program supervisor. Just click helloninepatch testing. |