android dev : looks like html dev
basic development routine:
get component findXXXById(R.id.XXX)
add event addXXXListener()
Common events: click, longClick, touch, key, focus
An important problem: the main thread, the UI thread, cannot be blocked, It will bring a bad user experience and will cause the system to pop up a warning.
Option 1, put the time-consuming task into a new thread.
Disadvantage: If you need to modify the properties of the view in a new thread, you need to call view.post() instead of calling it directly, otherwise an error will be reported. And this method will bring a lot of redundant code, which is not easy to maintain.
The second option is to create a SyncTask and implement the task method and callback method.
context: Two contexts, just like request, session, application
ActivityContext in web development, the entire activity cycle, the short time
ApplicationContext, the entire application cycle, the long time
Pop box:
Toast = Alert
notification:
NotificationCompat: Create a notify object, you can define: Title, Content, Ticker, Icon
NotificationManager: pop up a notify object
Resource management:
commonly used res, not commonly used asset
Three ways to reference res:
code:
Resource r = context.getResources()
R.ResourceType.ResourceNameXML
:
@[PackageName:]ResourceType/ResourceName
Resource structure:
res/
drawable:image
menu:menu
xml:
values/
dimens:dimensions
string:string
color: color
Component :
view : widget general component
viewgroup : layout component container
Component classification:
1, Basic: TextView, EditText, Button
2, Selection: TimerPicker, DatePicker
3, List: ListView, Spinner
4, Display image: Gallery, ImageSwitcher
5 , Menu:
6, Others: AnalogClock and DigitalClock
Components Size Properties:
Relative Settings:
layout_width
layout_height
Optional Value:
wrap_content Wraps the content, that is, grows or shrinks with the content
fill_parent fills the parent container. Once set, other size properties will not work.
Absolute setting:
width:
size: width, maxWidth, minWidth
Number of characters: ems, maxEms, minEms, MaxLenght
singleLine Single line, ellipsis will be displayed if it cannot be displayed
Height :
Size: height, maxHeight, minHeight
Number of characters Lines: lines, maxLines, minLines Line
spacing: lineSpacingExtra component font Color
: textColor Text size: textSize Unit sp Text position: gravity Button ImageButton src ToggleButton textOn,textOff Radio: RadioGroup onCheckedChangeListener RadioButton text,tag is often used for display, data storage Checkbox: CheckBox onCheckedChangeListener
Spiner: drop-down list
entries drop-down array
spinnerMode mode, dialoge, dropdown
can add adapter as data, extends BaseAdapter focus on implementing getCount(), getView()
Selected event: setOnItemSelectedListner() AlertDialog
: pop-up box
Builder
title, message,
three buttons: positiveButton, negativeButton,NeturalButton
options: itemsSingle choice
:
singleChoiceItemMultiple choice: mutiChoiceItem
custom: view Use view inflator
layout
Linear layout: table layout
LinearLayout
orientation = vertical or horizontal
gravity = center
weight According to the proportion, set in the child component
Code to generate the layout dynamically:
1. Pure code, rarely used
2. Loading reusable xml layout
View through LayoutInflator v = getLayoutInflator().inflate(R.layout.xxx,null);
this.layout.addView(v);
Relative Layout: div + css
RelativeLayout
Position: layout_above/below/toLeftOf/toRightOf
Offset: layot_marginTop/Buttom/Left/Right
Alignment: layout_alignXXX
Frame Layout:
FrameLayout
Table Layout
TableLayout
Scrollbar Layout
ScrollView
ListView
BaseAdapter Flexible
ArrayAdapter Simple
SimpleAdapter Simple
SimpleCursorAdapter Database
divider, dividerHeight dividing line color and thickness
headView, footView head and tail custom
GridView: grid
adapter
column column
Gallery: gallery
adapter
onItemSelected Click
GalleryParam width and height
DatePicker: date selection
init default value, select callback function after
calanderViewShow will display the date selection box by default
TimePicker: time selection
setIs24HoursView 24-hour
XXXDialog: pop-up box date and time selection
ProgressBar: progress bar The
default is a circle, and the long bar needs to be set with style="@android:style/Widget.ProgressBar.horizontal" The asynchronous processing method of
ProgressDialog Handler should be declared in the main thread, and the time-consuming task is executed in a new thread. After execution, call the sendMessage of the Handler to send a message and notify the CallBack; the handleMessage implemented in the CallBack can process the message and complete the control update; Activity -> Windows ->XXXLayout ->Component name, label is recommended to use wizard to generate jump Intent intent = new intent(); intent.setClass(this, SecondActivity.class); startActivity(intent) Android's return button, which will return the Activity pass value : intent.putExtra();
Get the value:
Intent intent=this.getIntent()
intent.getStringExtra();
setContentView(R.layout.myactivity) just redraws, will not enter the activity stack
to pass data to each other
The original Activity calls startActivityForResult() to jump
, and then the Activity calls setResult( ) returns data
The original Activity rewrites onActivityResult() to receive data
Crazy Android Notes:
Chapter 1
Development and History
The historical explanation is very interesting, add more pictures to increase the sense of familiarity
//Frame features are not friendly to beginners
Build a development environment
//Common development The usage of tools is not friendly to beginners. The simple explanation of
the first program can also be used for
Activity and layout
structure analysis. There is no need to manually create
R and res . The introduction of basic components of
AndroidManifest.xml can also be used. //The signature is not friendly to beginners . Chapter 2 Key Points There are too many attributes . There is no classification and explanation of the attributes. Forget about the container ViewGroup after reading it.
Control sub-components: ViewGroup.LayoutParams, ViewGroup.MarginLayoutParams
layout_height, layout_width : fill_parent/match_parent , wrap_content
The size of the component is controlled by its own size and the layout size above. It is recommended to use the layout size control, which will make the interface platform
independent Code control UI interface: cumbersome
Complete XML control UI interface: inflexible
Conclusion: Hybrid control
// The example is not very
clever Custom component interface:
// There are too many methods, the example is not very appropriate
Linear layout: no line break
// No attribute explanation Classification
Table layout:
A TableRow is a row, and each component in a TableRow is a column
Frame layout:
//The neon example is creative, but I forgot to talk about threads first.
Component
View
Android study notes
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326081644&siteId=291194637
Recommended
Ranking