Objective
Hello everyone, to bring you Android开发工程师文集-相关控件的讲解,五大布局
an overview, I hope you like
TextView controls
What are the properties of the TextView control:
android:id->控件的idandroid:layout_width->控件的宽度android:layout_height->控件的高度android:text->文本内容android:textSize->文本的大小android:textColor->文本的颜色android:background->控件的背景,可设置颜色或图片
EditText controls
What are the properties of the EditText control:
android:id->android:layout_width:android:layout_height:android:text:android:textSize:android:textColor:android:background://android:hint->输入提示android:inputType->输入的类型
Set color
- In XML, it's Android:textcolor.
- It's settextcolor in the activity.
Autocompletetextview
Autocompletetextview the prompt message that appears when you enter text automatically for the control.
Related properties:android:completionThreshold="2"
Example code:
private String[] strings={ "数据1","数据2",....};//初始化控件//需要适配器//初始化数据源//adpter-autocompleteTextViewautocompleteTextView = findViewById(R.id.autocompleteTextView);ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,strings);autocompleteTextView.setAdapter(adapter);
Multiautocompletetextview
The main thing is that you can select multiple values.
Here the main delimiter, you can enter multiple values
multiAutoCompleteTextView = findViewById(R.id.multiAutoCompleteTextView);multiAutoCompleteTextView.setAdapter(adapter);
Note To set the delimiter
multiAutoCompleteTextView.setTokenizer(new multiAutoCompleteTextView.CommaTokenizer());
ToggleButton
This ToggleButton has two states, one is selected and one is not selected.
Can be understood as the switch effect of the electric light, the property is:
android:checked="true"android:textOff="off"android:textOn="on"
The main methods of implementation:
@Overridepublic void onCheckedChanged(CompoundButton, buttonView, boolean isChecked){ //图片的切换 imgpicture.setBackgroundResource(isChecked?R.drawable.one:R.drawable.two);}
Intent jump
1. startActivity(intent);2. startActivityForResult(intent,requestCode);onActivityResult();//MainActivityonResult();
Next only Learn Startactivityforresult ():
Intent intent = new Intent(MainActivity.this,SecondActivity.class);startActivityForResult(intent,1);
Create the Onactivityresult () method with the mainactivity:
Receive the returned data
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data){ super.onActivityResult(requestCode, resultCode, data);}
So the method of creating Onresult () in secondactivity:
Callback Intent object, return data
Intent data=new Intent();data.putExtra("data",name);setResult(2,data);
Onactivityresult () in mainactivity:
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data){ super.onActivityResult(requestCode, resultCode, data); if(requestCode == 1 && resultCode == 2){ String name = data.getStringExtra("data"); tv.setText(name);}
Four components
Four components of Android
- Activity
- Service
- Broadcastreceiver
- Content Provider
Learn the life cycle of activity again
- OnCreate ();
- OnStart ();
- Onresume ();
- OnPause ();
- OnStop ();
- OnDestroy ();
- Onrestart ();
Four states of activity:
- Activity status
- Paused state
- Stop State
- Destroy state
A life of activity:
OnCreate ()->onstart ()->onresume ()->onpause ()->onstop ()->ondestroy ()
Start to backstage and then front desk:
OnCreate ()->onstart ()->onresume ()->onpause ()->onstop ()->onrestart ()->onstart ()->onresume ( )
To set the startup mode period for a small window:
Onresume () to get focus
OnPause () to lose focus
OnCreate ()->onstart ()->onresume ()->onpause ()->onresume ()
CheckBox and RadioButton
//核心if(isChecked){ String text = checkBox.getText().toString();}
Here RadioButton, pay attention to radiogroup on the line.
//核心@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId){ switch(checkedId){ case R.id.button1: break; case R.id.button2: break; default: }}
Of course here you can also use RadioButton to monitor, but personally think Radiogroup more convenient!
Five major layouts
LinearLayout:
android:orientation=""1. vertical2. horizontalandroid:gravity=""center,bottom,left,rightandroid:layout_gravity=""android:layout_weight=""//android:layout_height="match_parent"的比例为反,用android:layout_weight=""的话
- Layout_gravity adjust the position of the layout relative to the parent layout
- Gravity is where you adjust the layout of the sub-layout
- Horizontal linearlayout to start from the left to place the layout
4.layout_gravity only in the LinearLayout layout
Relativelayout:
Relative layout, we just need to know the corresponding property on the line:
android:layout_alignParentLeft="true"android:layout_alignParentTop="true"
android:layout_centerInParent="true"android:layout_centerHorizontal="true"android:layout_centerVertical="true"
android:layout_marginLeft="50dp"android:layout_marginBottom="50dp"
android:layout_toRightOf="@+id/button1"android:layout_toLeftOf="@+id/button2"android:layout_below="@+id/button1"//android:layout_alignBaseline="@+id/button1"
android:gravity=""
These are understood by means of English.
Framelayout:
The first place is below, all in the upper left.
Absolutelayout:
android:layout_x= "50dip"
Android:layout_y= "50dip"
Tablelayout:
Tablerow-view
Important attributes:
//都是从0开始的索引列android:collapseColumns="1,2"//隐藏android:shrinkColumns="1,2"//收缩android:strechColumns="1,2"//拉伸
android:layout_column="1"//显示在第二列android:layout_span="2"//这个表示一个空间占据两列
If you feel good, then you can order a praise!??
Summarize
- This article talks about the Android Development engineer Anthology-related controls, five layouts , if you have a better understanding, welcome to communicate
- Positioning: Sharing
Android
& Java
knowledge points, interested to continue to follow
Android Development Engineer Anthology-related controls explained, five layouts