Let's first look at the buttons. The text on the button shows that a large button, a small button, and a strange button. Well, let's say so much.
Let's talk about how the buttons are implemented first. Simply display the button above, you can add the corresponding component in Main. xml. Next let's add it!
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <scrollview xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent"> <br/> <linearlayout <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content"> <br/> <button <br/> Android: Id = "@ + ID/button_large" <br/> Android: TEXT = "@ string/button_large" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> <button <br/> Android: Id = "@ + ID/button_small" <br/> Android: TEXT = "@ string/button_small" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> <togglebutton <br/> Android: Id = "@ + ID/button_toggle" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/button_toggle" <br/> <imagebutton <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: src = "@ drawable/Change2" <br/> </linearlayout> <br/> </scrollview> <br/>
Does anyone ask why you must add it in Main. xml? Well, not necessarily. We can add all kinds of XX. xml by ourselves, and then call it in the corresponding activity. (Setcontentview (R. layout. xx ))
We can see that we have added three buttons, the first two of which are the same. There is no difference except that the ID and text are different. Why is the display different? I will tell you later. The third button is togglebutton, as the name suggests, the trigger button. The fourth is an image button.
Let's continue.CodeAndroid: Id = "@ + ID/button_small"
It is used to declare the ID resource attribute. @ + id can automatically add the attribute number for the resource. This resource is automatically recorded in class resource file R. java.Android: text = "XXXX"
Is used to add text for the build. You can directly specify the text or import it from the strings. xml file. However, you must first define it in strings. xml. The strings. xml file is as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <resources> <br/> <string name = "hello"> Hello world, buttontest! </String> <br/> <string name = "app_name"> buttontest </string> <br/> <string name = "button_large"> large button </string> <br/> <string name = "button_small"> small </string> <br/> </resources>
Android: layout_width and Android: layout_height are used to specify the button size. You can directly specify Android: layout_width = "50dip". Of course, we can also use three built-in system sizes: "full_parent", "wrap_content", and "match_parent ". Wrap_content allows the button size to overwrite the text. Full_parent matches the button with the length and width of the window. Match_parent is essentially the same as full_parent and replaces full_parent from API Level 8.
For image buttons, use the <imagebutton component. You need to import the corresponding image resources and put them under Res/drawable.
Now I know so much about it. I will continue to share my new knowledge in the future.