Guest User

Untitled

a guest
Dec 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. - Sizing using dp and sp:
  2. + dp use for sizing widget width and height
  3. + sp use for font size
  4. + determine by horizontal resolution / horizontal size in inches
  5.  
  6. - Sizing using match parent and wrap content
  7.  
  8. - Padding (inside) and margin (outside)
  9.  
  10. - Layout_weight: 1 of 2 height or width must set to 0 and layout_weight is apply for the property that set to 0. (Chia theo ti le)
  11.  
  12. - gravity: align content inside, layout_gravity: align widget position itself within a layout element
  13.  
  14. - Relative layout: children of the layout is relate to each others. Some important property:
  15. + android:layout_above:{id} => element will above the element that has id = id
  16. + android:layout_below:{id} => ....below...
  17. + android:layout_align[left|right...]="true"
  18. + android:margin...
  19.  
  20. - Linear layout:
  21. + vertical: the new added element will below the old element
  22. + horizontal: the new added element will on the right of old element
  23.  
  24. - scroll view can only has one child and usually is linear layout, once have linear layout, we can add as many widgets as we want and they will add scroll nicely
  25.  
  26. - hint property: the text will be put on the widget as soon as the user tap to it and enter text
  27.  
  28. - Usually design is linear layout on the top, we will devide it into many frames and each frames is relative layout
  29.  
  30. - Android life cycle:
  31. + Being created: onCreated
  32. + Starting: onStart
  33. + Resuming: onResume
  34. + Pausing: onPause
  35. + Running: onCreated + onStart + onResume
  36. + Stopping: onStop
  37. + Being destroy: onDestroy
  38.  
  39. + Setup the app ready to run in onCreated
  40. + Load user data in onResume
  41. + Save user data in onPause
  42. + Free memory in onDestroy
  43.  
  44. - About Android UI elements are class:
  45. + When our app is run and the setContentView method is called from onCreate, the layout is inflated from XML UI classes and loaded into memory as usable objects. They are stored in a part of the DVM memory called the heap
  46. + All objects of classes are reference type variables and are just references to the actual objects that are stored on the heap; they are not actual objects.
  47. + Regularly, while our app is running, the DVM will scan the stack, the regular racks of our warehouse, and match up references to objects that are on the heap. And it destroys any objects that it fnds without a matching reference
  48. + if an object has no reference variable, we can't possibly do anything with it anyway because we have no way to access it. This system of garbage collection helps our apps run more effciently by freeing up unused memory
  49. + Any UI element that has its id property set can have its reference retrieved from the heap using the findViewById method, which is part of the Activity, the AppCompatActivity class. As it is part of the class that we extend, we have access to it:
  50. myButton = (Button) findViewById(R.id.myButton);
  51. * Note myButton can exist in any xml file, but ro run without crash, the xml file that contain myButton must be inflated using setContentView so myButton object can load into heap and ready for using.
  52.  
  53.  
  54. - Ailias resource:
  55. + Create refs.xml file in values folder:
  56. <?xml version="1.0" encoding="utf-8"?>
  57. <resources>
  58. <item name = "activity_dualfragment" type= "layout">
  59. @layout/activity_main
  60. </item>
  61. </resources>
  62.  
  63. + Create refs.xml file in values-land folder:
  64. <?xml version="1.0" encoding="utf-8"?>
  65. <resources>
  66. <item name = "activity_dualfragment" type= "layout">
  67. @layout/activity_main_land
  68. </item>
  69. </resources>
  70.  
  71. + Create 2 layout files in layout folder: activity_main.xml and activity_main_land.xml
  72.  
  73. + We can setContentView like below:
  74. setContentView(R.layout.activity_dualfragment);
  75.  
  76. + This setContentView line of code passes the activity_dualfragment alias and not either of the actual layout fles. The two refs.xml fles each contain an alias for activity_dualfragment that will ensure that a different layout fle is used depending upon which orientation the device is in. So when the device is in the landscape orientation, activity_main_land will be loaded as the view, and when the device is in the portrait orientation, activity_main will be used.
Add Comment
Please, Sign In to add comment