Basics of UI Layouts design in Android
In Android all visual elements that make up a screen are Views and they are all children of View class.
They all share a similar property. Eg. All views have a width, height and background and they all can be made interactive.
We can also make our own CustomViews.
Most used View are :
- ImageView
- TextView
- Button
- EditText
- CheckBox
- Sliders
- Menus
- Color Pickers
Every View has a location expressed as a pair of left and top coordinates and 2-D a width and height. The unit for expressing location and dimensions is the density independent pixel (dp/dip)
Dp is an abstract unit that is based on the physical pixel density of the screen.
- On 160 dpi screen: 1dp == 1 pixels
- ON a 480 dpi , 1 dp == 3 pixels
For Text measurement we use sp (scale independent pixels) because it is not only scaled by the pixel density but also by the font size preference that the user can set in the phone settings.
ViewGroups : are the Views that contains other views. Eg. LinearLayout contains Views arranged in horizontal and vertical ways.
Constraint Layout : a Layout with flat view hierarchy and is optimised for laying out its views. We can build any layout using constraint layout. It is best for arranging a small number of views or ViewGroups in a complex layout that might otherwise require deep nesting.
Margin : spacing outside the view
Padding : spacing inside the view
android:lineSpacingMultiplier="1.2" add spacing between the lines of text
Comments
Post a Comment