Button, which is a button, is one of the most commonly used components in android. There are two ways to use Button, one is to configure it in XML, and the other is to use it directly in the program.
In the XML layout file Here, you will encounter the following units
px: pixels of the screen
in: inches
mm: millimeters
pt: pounds, 1 /72 inches
dp: An abstract unit based on density. If a 160dpi screen, 1dp=1px
dip: Equivalent to dp
sp: Similar to dp, But it also scales based on the user's font size preference.
It is recommended to use sp as the unit of text, and dip for others
Example 1: Layout in XML, it will be more convenient to modify the control in the future, and it also conforms to the MVC pattern
main.xml layout file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
TestButton.java source code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
Running results:
Of course, you can also use the corresponding method directly in the program to obtain the corresponding properties of Button
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
The above is the content of the Android UI control series: Button (button), more related Please pay attention to the PHP Chinese website (www.php.cn) for content!