"Alearning" chapter III Android Basic Common controls

Source: Internet
Author: User

This chapter mainly describes the basic common more used controls, including TextView, EditView, ImageView, button, and so on. This chapter describes the use of the basic properties of related controls and provides the basis for advanced learning in later chapters. The LinearLayout layout referenced in the case can be discussed in detail in the subsequent chapters.

TextViewTextView The basic properties of the control, android:layout_width the layout width android:layout_height the layout height. Both of these attribute parameters are required.
TextView android:layout_width and Android:layout_height parameters to choose from:
    • Match_parent: Match parent control size (width, height) "Official recommended"
    • Fill_parent: Padding parent control size (width, height) is equivalent to Match_parent
    • Wrap_content: Package Contents
TextView Properties of the extension:
  • Android:text The text of the specified control
  • Android:gravity The base position of the specified control
  • Android:drawablelef Specifies the drawable (slice) of the left output of the text
  • Android:drawableright Specifies the text to the right of the output drawable (slice)
  • Android:drawabletop Specifies the drawable (slice) of the text top output
  • Android:drawablebottom Specifies the text bottom output of the drawable (slice)
"Layout file" Activity_textview.xml.
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " > <textview android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android : gravity= "center" android:text= "TextView"/> <textview android:layout_width= "Match_parent" a        ndroid:layout_height= "Wrap_content" android:drawableleft= "@drawable/tupiao" android:gravity= "center" android:text= "Textview_drawableleft"/> <textview android:layout_width= "Match_parent" android:layou t_height= "Wrap_content" android:drawableright= "@drawable/tupiao" android:gravity= "center" Android:tex t= "Textview_drawableright"/> <textview android:layout_width= "match_parent" android:layout_height= " Wrap_content "Android:drawabletop= "@drawable/tupiao" android:gravity= "center" android:text= "Textview_drawabletop"/> <textview Android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:drawablebottom= "@dra Wable/tupiao "android:gravity=" center "android:text=" Textview_drawablebottom "/></linearlayout>

Effect:


EditText

EditText Control, mainly provides the user to fill in (input) information interface function, and previously introduced the TextView main role is the information display.
EditText android:layout_width and Android:layout_height parameters to choose from:
    • Match_parent: Match parent control size (width, height) "Official recommended"
    • Fill_parent: Padding parent control size (width, height) is equivalent to Match_parent
    • Wrap_content: Package Contents
EditText Properties of the extension:
    • Android:text The text of the specified control
    • Android:gravity The base position of the specified control
    • Android:password Specify text with a small dot "?" Show
    • Android:hint text message to display when text is empty
    • Android:drawablelef Specifies the drawable (slice) of the left output of the text
    • Android:drawableright Specifies the text to the right of the output drawable (slice)
    • Android:drawabletop Specifies the drawable (slice) of the text top output
    • Android:drawablebottom Specifies the text bottom output of the drawable (slice)
"Layout file" Activity_edittext.xml.
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " > <edittext android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android : gravity= "center" android:text= "EditText"/> <edittext android:layout_width= "Match_parent" a ndroid:layout_height= "wrap_content" android:gravity= "center" android:hint= "please input your message! "/> <edittext android:layout_width=" match_parent "android:layout_height=" Wrap_content "Android oid:drawabletop= "@drawable/tupiao" android:gravity= "center" android:hint= "please input your message! "/> <edittext android:layout_width=" match_parent "android:layout_height=" Wrap_content "Android oid:drawabletop= "@drawable/tupiao" Android:gravity= "center" android:text= "EditText"/> <edittext android:layout_width= "Match_parent"        android:layout_height= "Wrap_content" android:drawableleft= "@drawable/tupiao" android:gravity= "center" Android:password= "true" android:text= "EditText"/></linearlayout>
Effect:


ImageView

The ImageView control mainly provides the function of the picture display, but when the basic control is understood, it is found that many of these basic controls can be used universally, such as the button's Click event Listener operation.
ImageView android:layout_width and Android:layout_height parameters to choose from:
    • Match_parent: Match parent control size (width, height) "Official recommended"
    • Fill_parent: Padding parent control size (width, height) is equivalent to Match_parent
    • Wrap_content: Package Contents
ImageView Properties of the extension:
    • ANDROID:SRC specifying foreground drawable (slices)
    • Android:background Specifying background drawable (slices)
Note:the background is stretched according to the length and width given by the ImageView component, while SRC stores the size of the original and does not stretch. SRC is the picture content (foreground), background is the background and can be used simultaneously.
"Layout file" Activity_imageview.xml.
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "vertical" >    <imageview        android:layout_width= "match_parent"        android:layout_height= "Wrap_content"        android:src= "@drawable/image"/>    <imageview        android:layout_width= "Match_ Parent "        android:layout_height=" wrap_content "        android:background=" @android: Color/background_dark "        android:src= "@drawable/image"/></linearlayout>

Effect:


Button ImageButton

The button control, from the name itself can be very clear, provide the control of the buttons, and ImageButton more obvious is to provide the picture button.
Button/imagebutton android:layout_width and Android:layout_height parameters to choose from:
    • Match_parent: Match parent control size (width, height) "Official recommended"
    • Fill_parent: Padding parent control size (width, height) is equivalent to Match_parent
    • Wrap_content: Package Contents
Button/imagebutton Properties of the extension:
    • ANDROID:SRC specifying foreground drawable (slices)
    • Android:text Invalid for ImageButton control
    • Android:background specifying foreground drawable (slices)
"Layout file" Activity_button.xml.
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "vertical" >    <button        android:layout_width= "match_parent"        android:layout_height= " Wrap_content "        android:text=" button "/>    <button        android:layout_width=" Match_parent        " android:layout_height= "Wrap_content"        android:background= "@drawable/button"        android:text= "button"/ >    <imagebutton        android:layout_width= "match_parent"        android:layout_height= "Wrap_content"        android:background= "@drawable/button_with_text"/></linearlayout>

Effect:

There are many kinds of controls commonly used in Android, this chapter mainly introduces these more commonly used controls to facilitate the use of subsequent chapters and pave the way for the introduction of new knowledge points. This chapter concludes our study, so please look forward to the next section.

Resources1, http://www.uuton.com/post/3f493_1b87532, http://blog.163.com/allegro_tyc/blog/static/33743768201371301526104/

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.