1. Android relativelayout attributes
// Relative to the given ID Control
Android: layout_above: place the bottom of the control on the control with the given ID;
Android: layout_below: place the bottom of the control under the control with the given ID;
Android: layout_toleftof align the right edge of the control with the left edge of the control with the given ID;
Android: layout_torightof align the left edge of the control with the right edge of the control with the given ID;
Android: layout_alignbaseline: Align the baseline of the control with the baseline of the given ID;
Android: layout_aligntop: Align the top edge of the control with the top edge of the given ID;
Android: layout_alignbottom: Align the bottom edge of the control with the bottom edge of the given ID;
Android: layout_alignleft: Align the left edge of the control with the left edge of the given ID;
Android: layout_alignright: Align the right edge of the control with the right edge of the given ID;
// Relative to the parent component
Android: layout_alignparenttop if it is true, align the top of the control with the top of its parent control;
Android: layout_alignparentbottom: If this parameter is set to true, the bottom of the control is aligned with the bottom of its parent control;
Android: layout_alignparentleft: if it is true, align the left of the control with the left of its parent control;
Android: layout_alignparentright: if it is set to true, align the right of the control with the right of its parent control;
// Center
Android: layout_centerhorizontal if true, place the control horizontally in the center;
Android: layout_centervertical if true, place the control vertically in the center;
Android: layout_centerinparent if true, place the control in the center of the parent control;
// Specify the moving Pixel
Android: layout_margintop offset value;
Android: layout_marginbottom offset value;
Android: layout_marginleft value of the left offset;
Android: value of the right offset of layout_marginright;
Example:
Android: layout_below = "@ ID /***"
Android: layout_alignbaseline = "@ ID /***"
Android: layout_alignparenttop = true
Android: layout_marginleft = "10px"
2. Some common public attributes
1) layout_width-Width
Fill_parent: the width is the same as that of the parent element. wrap_content: The width varies with the content, or the PX value is specified to set the width.
2) layout_height-height
Fill_parent: The height is the same as that of the parent element. wrap_content: The height varies with the content, or the PX value is specified to set the height.
3) Background-set the background image
4) padding-set margins
You can set paddingbottom, paddingleft, paddingright, and paddingtop to set different PX values.
5) ID-ID of the object
@ + ID/id1 indicates to add a new id named id1, and @ ID/id1 indicates to reference the id1 control.
6) layout_weight-importance
The Display priority. The default value is 0 (highest). The greater the value, the lower the priority! Refer to the following linear
Layout example. To make layout_weight take effect, the corresponding parent layer or parent layer must be
Layout_width/layout_height = "fill_parent"; otherwise, wrap_content
Will be compressed to the minimum enough space!
7) alignment of layout_gravity-container component
Alignment of Components in layout.
8) gravity-alignment of text in components
For example, set the text in the button to center in the button.
* For most attributes, you can call the corresponding function to dynamically change the status. Please refer to the SDK Doc.
2. Linear layout linear Layout
Orientation-Arrangement of elements in a container. Vertical: child elements are vertically arranged, horizontal:
Child elements are arranged horizontally. You can use setorientation () to dynamically change the code,
The values are horizontal and vertical.
* In linear layout, the width and height are all occupied by components one by one! Therefore, when a component is set
"Fill_parent", if layout_weight is not set, this component occupies the remaining space,
The components after it cannot be displayed. For example, if edittext is not set
Android: layout_weight = "1", other components under it will be invisible!
Baselinealigned, which defaults to true, indicates that all components in the same direction are based on
Align the first component. So we can see that text1, button1, and text2 are in the same horizontal line.
If this effect is not required, set it to false.
3. common android controls
1, edittext
Main functions: settext/gettext setting/getting text content. sethint sets the default display content;
2, radiogroup, radiobutton
Radiobutton's ischecked () determines whether it is selected
Obtain the ID of the selected radiobuton: sets the radiogroup. setoncheckedchangelistener method.
Public oncheckedchanged (radiogroup group, int checkedid) // checkedid is the ID of the selected radiobutton.
3, checkbox
Ischecked () determines whether it is selected
The setoncheckedchangelistener method monitors changes in the selected status.
4, Spinner
A. Display Data
1), hard encoding Loading
Use the setadapter method to set the type to arrayadapter (context, int textviewresid, string [] objects)
Textviewresourceid: The viewid of the displayed content is set to R. layout. simple_spinner_item by default.
Objects: displayed content
2) load from the resource file
Arrayadapter. createfromresource (context, int textarrayresid, int textviewresid) // textarrayresid is the resource ID
Returns arrayadapter <charsequence>
B. Set the style of the drop-down list (optional)
Adapter. setdropdownviewresource (Android. R. layout. simple_spinner_dropdown_item );
C. Select a change event as the listener.
Setonitemselectedlistener
The Spinner. onitemselectedlistener class must implement the following two methods:
Public void onitemselected (adapterview <?> Parent, view, int position, long ID) // view the selected instance and position of the selected item in the adapter
Public void onnothingselected (adapterview <?> Arg0)
D. Set the selected items.
Spinner. setselection (position) // index starts from 0
D. Obtain the selected items.
Getselecteditemposition ()
Getselecteditem () // The value of tostring () is the string of the selected content
Getselecteditemid ()
Getselectedview ()
5. autocompletetextview
1. setadapter: Set the data adapter
2. The autocompletetextview. setthreshold (INT threshold) prompt is displayed)
6. multiautocompletetextview (multi-value input is allowed. Multiple values are automatically separated by the specified separator)
1. setadapter: Set the data adapter
2. When settokenizer is set, the default tokenizer is new multiautocompletetextview. commatokenizer (), which is separated by commas.
7, datepicker, timepicker
A, datepicker
1), set the initial display date Init (INT year, int month, int day, new datepicker. ondatechangedlistener (){
Public void ondatechanged (datepicker view, int year, int monthofyear, int dayofmonth ){}
})
2), get the set value getyeah ()/getmonth ()/getdayofmonth ()
B, timepicker
1), set setcurrenthour (integer currenthour)/setcurrentminuter (integer currenthour)
2. Set setis24hourview (Boolean) to 24-hour display.
3. The Listener settings change setontimechangedlistener.
C. Obtain the current system time and date.
Calendar. getinstance () returns calendar
Calendar. Get (INT field) --- the field can be calendar. Year/calendar. Month/calendar. day_of_month/Calendar ar. hour_of_day/calendar. Minute
8, imageview/imagebutton
Main Method
Setimageresource
Setalpha: Set alpha
Invalidate force update
Setscaletype (scaletype st) sets the image display mode. St is an enumeration.
Setadjustviewbounds: Set whether to adjust the widget to adapt to the image size.
Setbackgroundresource
9. imageswitcher (displays a series of images, but only one image is currently displayed)
Show data
Setfactory (viewswitcher. viewfactory factory) sets the data to be displayed
The viewfactory interface must implement the public view makeview () {} method to provide the currently displayed view (imageview), and the view must be a new instance.
Method
Setimageresource: Set the currently displayed Image
Getcurrentview () returns the currently displayed view
Setinanimation (animation ANI) sets the animation effect when a view is loaded. animationutils. loadanimation (context, int ID) gets the animation effect Android. R. anim. xx
Setoutanimation (animation ANI) sets the animation effect when a view is loaded.
10. Gallery (displays a series of images and provides special effects such as dragging)
Show data
Setadapter (spinneradapter adapter) sets the data adapter.
The data adapter can be inherited from baseadapter. The public view getview (INT position, view convertview, viewgroup parent) class returns the current selected view (imageview)
Select to listen to setonitemselectedlistener
11. gridview (a series of images are displayed in the table)
Show data
Setadapter (listadapter adapter) sets the data adapter.
The data adapter can be inherited from baseadapter. The public view getview (INT position, view convertview, viewgroup parent) class returns the current selected view (imageview)
Select to listen to setonitemselectedlistener
Getselectedview () returns the currently selected view
12, scrollview
13. progressbar
Setindeterminate: Set whether the progress bar is automatically running
Setprogressstyle set the display style. progressdialog. style_horizontal/progressdialog. style_spinner
Setprogress setting progress
Setmax sets the maximum value.
Getprogress () Get the current progress
14. seekbar
Method
Setmax sets the maximum value.
Getprogress () Get the current value
Setprogress Setting Value
Setindeterminate
Listener
There are three methods under setonseekbarchangelistener
Public void onprogresschanged (seekbar arg0, int arg1, Boolean arg2) // numeric value change, new arg1 value, touch or not
Public void onstarttrackingtouch (seekbar) // start dragging
Public void onstoptrackingtouch (seekbar) // end dragging
15. listview
A. display the setadapter (listadapter adapter) data)
The adapter can be new simplecursoradapter/simpleadapter (context, int layout, cursor C, string [] From, int [])
Layout is a template used to display data. Android. R. layout. simple_list_item_1 can be used to display one column. Android. R. layout. simple_list_item_2 can be used.
For multiple columns, you must implement the XML view layout file by yourself.
C Data (arraylist can be used to construct data)
From ':
To is used to display the empty parts ID of the corresponding column
B. dynamically add and delete data
Adapter. notifydatasetchanged ()
D. Set the background color.
Setbackgroudrource