Android UI native-(1), Android UI entry and common attributes and phenomena, androidui
Reprinted please indicate this article is from the JFlex blog!
Android UI native-(1), Android UI entry, and common attributes and Phenomena
Guide: Getting started with the Android UI is relatively simple for many people, and there are many tutorials, but this article is definitely different from other ones. From access to android development, it is doomed that UI development is a subject that requires research all the time. You may have mastered the use of simple native UI and may find some components uncomfortable, but as long as you understand the reasons, you can. I really feel uncomfortable using it, so I can make my UI development stronger, and then write a better one myself. Android UI development requires first learning to use the native UI, then learning to use the open source UI, and finally customizing the UI. In this order, the android UI development capability will be continuously improved.
1. Let's take a look at android UI1, xml, and code to draw UI2 respectively. How to color the UI and adapt resources?
International processing (multi-language)
The international processing is mainly reflected in res. Solution
Values Folder: values-country language
For example:
American English environment: values-en-rUS
Chinese environment: values-zh
Chinese environment in mainland China: values-zh-cn
For more information, see the Locale class.
The configuration of image resources and other resources is the same2. What should I do if the resolution is large or small?
Resolution adaptation is essential for android development.
The general processing method is: layout, which defines the component sizes required by dimens to process different resolutions in values with different resolutions.
1. Common Layout
LinearLayout: Linear layout, vertical and horizontal settings, more use
RelativeLayout: relative layout, used more
FrameLayout: layer layout, multi-layer View overlays.
TableLayout: table layout, just like the table in html
2. Use dimens more
3. UI development best practices
- Layout should use the least number of controls to meet the requirements and avoid repeated
- Complex layout, multiple use
<inflate>
- Id naming convention: component abbreviation + service name. The following is the abbreviation of some components.
- LayoutView: lv
- RelativeView: rv
- TextView: TV
- ImageView: iv
- ImageButton: im
- Button: btn
- Multiple styles are used to extract the same style from layout.
- . 9 create a chart
- Eliminate the use of px
- Use strings. xml, dimens. xml, and colors. xml values in layout.
2. Common Component Attribute manuals
1. General Attributes
Common attributes of android namespaces
-Width: layout_width
Values: wrap_parent (dynamically calculated based on content), match_parent (full parent layout), and specific dp
Platform |
Android |
IOS |
Html |
|
Layout_width |
Width |
Width |
-Height: layout_height
Valid values: wrap_parent, match_parent, and specific dp.
Platform |
Android |
IOS |
Html |
|
Layout_height |
Height |
Height |
-Layout_gravity
Platform |
Android |
IOS |
Html |
|
Layout_gravity |
None |
None |
-Gravity
Platform |
Android |
IOS |
Html |
|
Gravity |
None |
None |
-Padding between controls: padding
Platform |
Android |
IOS |
Html |
|
Padding |
None |
Padding |
-PaddingLeft
Platform |
Android |
IOS |
Html |
|
PaddingLeft |
None |
Padding |
-PaddingTop
Platform |
Android |
IOS |
Html |
|
PaddingTop |
None |
Padding |
-PaddingRight
Platform |
Android |
IOS |
Html |
|
PaddingRight |
None |
Padding |
-PaddingBottom
Platform |
Android |
IOS |
Html |
|
PaddingRight |
None |
Padding |
-Distance from parent control: margin
Platform |
Android |
IOS |
Html |
|
Margin |
None |
Margin |
-MarginLeft
Platform |
Android |
IOS |
Html |
|
MarginLeft |
None |
Margin |
-MarginTop
Platform |
Android |
IOS |
Html |
|
MarginTop |
None |
Margin |
-MarginRigth
Platform |
Android |
IOS |
Html |
|
Marginri.pdf |
None |
Margin |
-MarginBottom
Platform |
Android |
IOS |
Html |
|
MarginBottom |
None |
Margin |
2. LinearLayout
- Direction: orientation
Value: vertical or horizontal
Platform |
Android |
IOS |
Html |
|
Orientation |
None |
None |
3. RelativeLayout
The main attribute configuration of RelativeLayout is actually configured in its sub-controls.
- Align Series
Layout_alignParentLeft: relative to the left of the parent control. The value is true or false.
Layout_alignParentTop: relative to the top of the parent control. The value is true or false.
Layout_alignParentRight: relative to the right of the parent control. The value is true or false.
Layout_alignParentBotton: relative to the bottom of the parent control. The value is true or false.
Layout_alignLeft: The left side of the control. Value id
Layout_alignTop: relative to the top of the control, value id
Layout_alignRight: The right of the Control. Value id
Layout_alignBottom: relative to the bottom of a control, value id
- Center Series
Layout_centerHorizontal: center horizontally. The value is true or false.
Layout_centerVertical: center vertically. The value is true or false.
Layout_centerInParent: center horizontally and vertically. It is equivalent to true for both of the preceding values. The value is true or false.
3. Use custom component attributes 1. Custom Components
- Composite Control: binds existing controls to form new components. The simplest way is to implement it through inflate layout.
- Custom Property Control: To improve the configurability of custom components, you can view the desired effect in real time in layout by defining properties.
2. Packaging custom components
- Java-only components: directly package jar
- Components include layout: lib mode or (jar + res)
Iv. Native component common symptom 1. repeated call of getView of Adapter
For example, ListView: If the height of ListView is set to wrap_parent, getView is executed repeatedly. If the value of match_parent is set, it is normal.
2. nesting between ScrollView, ListView, and GridView
The height of ListView or GridView usually appears in nesting mode and only one row is displayed. You need to override the onMeasure method.
3. overScrollMode of a sliding View, such as ListView and GridView
By default, overScroll is a color animation that achieves a bounce effect similar to that of iOS. However, it is hidden to avoid the iOS bounce effect patent.
V. Final
This blog post will be updated occasionally. due to incomplete time and thinking, it will be added. I hope you will give more comments.