Common android controls

Source: Internet
Author: User

The components in android are everything, from simple buttons to complex webviews.
In this case, you can use as many widgets as possible on the registration interface. Controls involved in this case include TextView, EditText, RadioButton, Button, ToggleButton, CheckBox, and Spinner.
The overall layout structure of this case is as follows:


 
The main. xml code in MainActivity. java is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<TextView
Android: id = "@ + id/tvTitleRegister"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "user registration interface"
Android: textColor = "# EEE"
Android: textStyle = "bold"
Android: textSize = "28sp"
Android: layout_gravity = "center_vertical"
Android: gravity = "center"
/>
<TextView
Android: id = "@ + id/tvUserName"
Style = "@ style/TextViewTitleWidgetStyle"
Android: text = "User name :"
Android: layout_below = "@ + id/tvTitleRegister"
Android: layout_alignParentLeft = "true"
Android: layout_marginTop = "8dp"
/>
<EditText
Android: id = "@ + id/etUserName"
Style = "@ style/EditTextInputWidgetStyle"
Android: layout_toRightOf = "@ + id/tvUserName"
Android: layout_alignParentRight = "true"
Android: layout_below = "@ + id/tvTitleRegister"
Android: layout_marginLeft = "2dp"
Android: layout_marginRight = "2dp"
/>
<TextView
Android: id = "@ + id/tvUserPassword"
Style = "@ style/TextViewTitleWidgetStyle"
Android: text = "User Password :"
Android: layout_below = "@ + id/tvUserName"
Android: layout_alignParentLeft = "true"
Android: layout_marginTop = "26dp"
/>
<EditText
Android: id = "@ + id/etUserPassword"
Style = "@ style/EditTextInputWidgetStyle"
Android: layout_toRightOf = "@ + id/tvUserPassword"
Android: layout_alignParentRight = "true"
Android: layout_below = "@ + id/etUserName"
Android: layout_marginLeft = "2dp"
Android: layout_marginRight = "2dp"
Android: layout_marginTop = "5dp"
/>
<TextView
Android: id = "@ + id/tvSex"
Style = "@ style/TextViewTitleWidgetStyle"
Android: text = "Sex :"
Android: layout_below = "@ + id/tvUserPassword"
Android: layout_alignParentLeft = "true"
Android: layout_marginTop = "25dp"
/>
<RadioGroup
Android: id = "@ + id/radioSexGroup"
Android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"
Android: layout_alignParentRight = "true"
Android: layout_below = "@ + id/etUserPassword"
Android: layout_marginLeft = "2dp"
Android: layout_marginRight = "2dp"
Android: layout_toRightOf = "@ + id/tvSex"
Android: orientation = "horizontal"
>
<RadioButton
Android: id = "@ + id/radioMale"
Android: text = "male"
Android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"
Android: layout_marginLeft = "5dp"
/>
<RadioButton
Android: id = "@ + id/radioFemale"
Android: text = "female"
Android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"
Android: layout_marginLeft = "15dp"
/>
</RadioGroup>
<TextView
Android: id = "@ + id/tvMarriage"
Style = "@ style/TextViewTitleWidgetStyle"
Android: text = "Marital status :"
Android: layout_below = "@ + id/tvSex"
Android: layout_alignParentLeft = "true"
Android: layout_marginTop = "20dp"
/>
<ToggleButton
Android: id = "@ + id/tbIsGetMarried"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_toRightOf = "@ + id/tvMarriage"
Android: layout_below = "@ + id/radioSexGroup"
Android: layout_marginLeft = "5dp"
/>
<TextView
Android: id = "@ + id/tvhobbies"
Style = "@ style/TextViewTitleWidgetStyle"
Android: text = ":"
Android: layout_below = "@ + id/tvMarriage"
Android: layout_alignParentLeft = "true"
Android: layout_marginTop = "20dp"
/>
<CheckBox
Android: id = "@ + id/cb_basketball"
Style = "@ style/CheckBoxWidgetStyle"
Android: layout_below = "@ + id/tbIsGetMarried"
Android: layout_toRightOf = "@ + id/tvhobbies"
Android: text = "basketball"
Android: layout_marginLeft = "5dp"
/>
<CheckBox
Android: id = "@ + id/cb_Reading"
Style = "@ style/CheckBoxWidgetStyle"
Android: layout_below = "@ + id/tbIsGetMarried"
Android: layout_toRightOf = "@ + id/cb_basketball"
Android: text = "read"
Android: layout_marginLeft = "5dp"
/>
<CheckBox
Android: id = "@ + id/cb_pc"
Style = "@ style/CheckBoxWidgetStyle"
Android: layout_below = "@ + id/cb_basketball"
Android: layout_toRightOf = "@ + id/tvhobbies"
Android: text = "computer"
Android: layout_marginLeft = "5dp"
/>
<CheckBox
Android: id = "@ + id/cb_Sing"
Style = "@ style/CheckBoxWidgetStyle"
Android: layout_below = "@ + id/cb_Reading"
Android: layout_toRightOf = "@ + id/cb_pc"
Android: text = "singing"
Android: layout_marginLeft = "5dp"
/>
<TextView
Android: id = "@ + id/tvTitle"
Style = "@ style/TextViewTitleWidgetStyle"
Android: text = "Duty :"
Android: layout_below = "@ + id/tvhobbies"
Android: layout_alignParentLeft = "true"
Android: layout_marginTop = "60dp"
/>
<Spinner
Android: id = "@ + id/position"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_toRightOf = "@ + id/tvTitle"
Android: layout_marginLeft = "5dp"
Android: layout_below = "@ + id/cb_Sing"
/>
<Button
Android: id = "@ + id/bt_ OK"
Android: layout_width = "80dp"
Android: layout_height = "wrap_content"
Android: layout_alignParentBottom = "true"
Android: text = "register"
Android: layout_marginLeft = "65dp"
/>
<Button
Android: id = "@ + id/bt_Cancel"
Android: layout_width = "80dp"
Android: layout_height = "wrap_content"
Android: layout_alignParentBottom = "true"
Android: layout_toRightOf = "@ + id/bt_ OK"
Android: text = "cancel"
Android: layout_marginLeft = "5dp"
/>
</RelativeLayout>
Values/style. xml file
We recommend that you put some common attributes of the same control in the style. xml file.
1. Improve code reuse rate
Second: Facilitate later maintenance
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<! -- TextView -->
<Style name = "TextViewTitleWidgetStyle">
<Item name = "android: layout_width"> wrap_content </item>
<Item name = "android: layout_height"> wrap_content </item>
<Item name = "android: textColor"> # EEE </item>
<Item name = "android: textStyle"> bold </item>
<Item name = "android: textSize"> 18sp </item>
</Style>

<! -- EditText -->
<Style name = "EditTextInputWidgetStyle">
<Item name = "android: layout_width"> wrap_content </item>
<Item name = "android: layout_height"> wrap_content </item>
<Item name = "android: lines"> 1 </item>
</Style>

<! -- CheckBox -->
<Style name = "CheckBoxWidgetStyle">
<Item name = "android: layout_width"> wrap_content </item>
<Item name = "android: layout_height"> wrap_content </item>
</Style>
</Resources>
2011.10.19
Jack. li
QQ: 523072842

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.