[Android-Kotlin] study notes

1. Controls

  1. Genymotion virtual machine and plus
  2. drawable-24 is used to put vector graphics
  3. ConstraintLayout layout can add percentage auxiliary line to help adapt
  4. The right side is multi-selection and then aligned in one way, which is also very easy to use
  5. Picture references such as R.drawable.apple can be stored in int type picture id
  6. style: This resource directory is used to place various themes for ToolBar or other controls such as portals
    Insert picture description here
  7. Regarding so many texts, the first one is label, Plain Text is fully displayed, Password is *****, Number will only pop up the numeric keyboard (emmm, so some only fill in the numeric verification code but jump out of the full keyboard is The programmer is lazy)
    Insert picture description here
  8. calendar
    Insert picture description here
  9. Rating stars
    Insert picture description here
  10. Screen flip
  11. Two sets of layouts can be done in horizontal and vertical mode.

2. Localization (adapt to multiple languages)

1)
Insert picture description here
Go to the values ​​folder, open strings.xml, and use open editor 2) Click on the small globe and look for simplified Chinese (Minima is localized and powerful)
Insert picture description here
3) Add the corresponding conversion language
Insert picture description here
4) The corresponding folder is generated
Insert picture description here

2.5 Use layout_marginStart and End to replace Left and Right

Insert picture description here

2.6 clipToPadding 和 clipChildren

  1. LinearLayout can also make a bottom with a bottom beyond the boundary (for example, the width is set to 0, and the weight of the four FrameLayout is one). The properties are all true by default.
    1) If clipToPadding is false, it means that the padding area inside the view can also display the view.
    2) If clipChildren is false, it means that even if the child view inside the layout is outside the boundary of the layout, the child view interface can be displayed.
  1. Pay attention to clipToPadding. Use this carefully. Don't just write it without nesting (anywhere), and weight=1 and other layouts may be combined into unclear effects.
    4) Good-looking example
    5) If the child control exceeds the parent control, the android:clipToPadding and android:clipChildren attributes of the parent control must be set to false. Sometimes we find that the parent control has set these two attributes, and the child control is still clipped , This is because the space of the parent control is not enough, that is, the parent control is cropped. At this time, we need to set the property of the parent control of the parent control to false. Haha, but don't just add it to the summary, which is to set the properties of which control space you want to occupy.
 List<Integer> idlistgroup = Arrays.asList(
            R.id.first,
            R.id.second,
            R.id.third,
            R.id.forth)

2.7 Interface writing: two ways

3. A class in ViewModel-jetpack (a component of the androidx library)

  1. ViewModel is part of jetpack architecture components
  2. Make the interface Activity and Fragment UI only control the interface, and hand over the code data operation to the ViewModel to decouple
  3. Store Activity data, when the ac is not destroyed, the data will not be lost when the screen is redrawn (switching language, rotating the screen)
  4. ViewModelProviders have been deprecated and changed to ViewModelProvider samples
    Insert picture description here
  5. Cooperate with LifeData to complete the monitoring of dynamic data (automatically refresh data changes, and complete database storage in conjunction with Room.
    Insert picture description here

4. The relationship between the three

1. MVC->MVVM can extract the operation of the data in the C layer to the ViewModel to complete

Insert picture description here

2. Introduce the observer concept of LiveData , automatically monitor data changes and update the interface, greatly simplifying Controller operations

Insert picture description here

3. If you add DataBinding again, you can completely break away from the coupling of the C and V layers, greatly reducing the dependence on C, and it will be more flexible when the View changes

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_38304672/article/details/106292991