How to set the rounded corner button?

Source: Internet
Author: User

How to set the rounded corner button?

Why? Do you think Google's official buttons are ugly? Haha ~~ Here we provide some ideas on how to set the rounded corner for the button:

In Android, setting the background for a control (or View) is mainly done through the background: xxx attribute. The background parameter is generally a drawable resource. Drawable can be a normal image, a 9 patch image, or an xml file.

Method 1: Image

The easiest way to configure borders for a widget is to set the background as a background image with rounded corners and borders that you designed in advance.

However, you will soon find a drawback: poor flexibility! Yes, it is difficult to resize a fixed-size Image Based on the content in the control. It was confirmed on the day it was made! In other words, it is difficult for you to use only this image to deal with controls of the same style but different sizes. To add rounded corners and borders to all controls, you must carefully calculate their sizes and create background images one by one! Oh, that's silly. Once a variable-Size Control is encountered, this method will stop. In addition, a large number of background images will quickly expand your installation package. Er ...... Also, how do you deal with Android devices with various resolutions?

So, you need ...... Change the method.

The solution adopted by zookeeper is NinePatch. It is no exaggeration to say that patch 9 is a powerful tool in Android to solve adaptive problems.

Zookeeper has many advantages in using 9 patch images, such as reducing the stress on the artist, reducing the amount of UI code, and reducing memory usage ...... To sum up, it is time-saving and effort-saving.

Zookeeper, of course, 9 patch can do much more than this, such as making an adaptive dialog box or something. The end of a general 9patchimage is .9.jpg.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.