Some Base Widget in Android App
Some common controls in Android Applications
Several basic properties of control
- ID control ID
- layout_ Width: Wrap_ Content or match_ parent
- layout_ Height: Wrap_ Content or match_ parent
- Background: color / picture
1. Display control
Textview text
<TextView
android:id="@+id/tv_user_label"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text= "User name"
android:gravity="center"
android:textSize="24sp"
android:textColor="#0000FF"
android:textStyle="normal"
android:singleLine="true"
android:ellipsize="start"/>
Main attributes:
- Text text (recommended, refer to string.xml The elements inside)
- Textsize font size
- Textcolor font color
- TextStyle font formats are normal, bold and italics
- Position of gravity text display: top, bottom, left, right, center
- Does singleline display all content in one line
- Ellipsis: start, middle, end, marquee
ImageView image
Main attributes:
-
scaleType:
- Fitxy: display the original image in the view according to the specified size, stretch the image, do not maintain the original scale, and fill the imagebutton
- Center: displays the image in the center of the view without zooming the image
- Centrrop: scale the image so that the length (width) of the image is greater than or equal to the corresponding dimension of the view
- Centerside: scale the image to make the length (width) of the image less than or equal to the corresponding dimension of the view
- Fitcenter: scale the image to the smallest edge of the view and center it
- Fit: scale the image to the smallest edge of the view and display it in the lower part of the view
- Fitstart: scale the image to the smallest edge of the view and display it in the upper part of the view
- Matrix: drawing with a matrix
- SRC image source: @ drawable / beautiful, put the image in RES / drawable folder
Using glide to load network pictures
Glide.with(getContext())
.load("http://*.jpg")
.into(imageDetail);
2. Form control
EditText
Main attributes:
- Text text content: text or reference values below string.xml The elements in it
- Hint text prompt content
- Password: the input content is set to password type, true
- Phonenumber: the input content is set to phonenumber type, true
- Cursorvisible sets the cursor to show / hide: the default is true
Common callbacks:
val etName = findViewById<EditText>(R.id.et_username)
etName.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
//Monitor after input
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
//Monitor after input
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
//Input text change monitoring}
}
})
- Addtextchangedlistener monitors changes in the input box
- Setonfocuschangelistener listens for input focus changes
CheckBox
Main attributes:
- Is ischecked selected
Common callbacks:
- Setoncheckedchangelistener listens for state changes
Radio
Main attributes:
- Is ischecked selected
Common callbacks:
- Setoncheckedchangelistener listens for state changes
Seekbar slider
Main attributes
- Max the maximum value of the slider
- The current value of the progress slider
- Thumb slide background
- Progressdrawable reference background
Common callbacks:
- Setonseekbarchangelistener listens for changes in values
Switch
Main attributes:
- Is ischecked selected
Common callbacks:
- Setoncheckedchangelistener listens for state changes
CalendarView
Main attributes:
- Maximum date supported by maxdate: “07 / 27 / 2019 is set in mm / DD / yyyy format
- Minimum date supported by mindate: “07 / 27 / 2019 is set in mm / DD / yyyy format
- The first day of week is set as the first day of each week (the number 3 corresponds to Tuesday, 4 corresponds to Wednesday, and 1 corresponds to Sunday)
Common callbacks:
- Setondatechangelistener listens for changes in values
Button
Common callbacks:
- Setonclicklistener listens for state changes