Tutorial by Examples

The LinearLayout is a ViewGroup that arranges its children in a single column or a single row. The orientation can be set by calling the method setOrientation() or using the xml attribute android:orientation. Vertical orientation : android:orientation="vertical" <?xml version=&quo...
RelativeLayout is a ViewGroup that displays child views in relative positions. By default, all child views are drawn at the top-left of the layout, so you must define the position of each view using the various layout properties available from RelativeLayout.LayoutParams. The value for each layout...
android:layout_gravity android:layout_gravity is used to set the position of an element in its parent (e.g. a child View inside a Layout). Supported by LinearLayout and FrameLayout android:gravity android:gravity is used to set the position of content inside an element (e.g. a text insid...
GridLayout, as the name suggests is a layout used to arrange Views in a grid. A GridLayout divides itself into columns and rows. As you can see in the example below, the amount of columns and/or rows is specified by the properties columnCount and rowCount. Adding Views to this layout will add the fi...
2.3 The Percent Support Library provides PercentFrameLayout and PercentRelativeLayout, two ViewGroups that provide an easy way to specify View dimensions and margins in terms of a percentage of the overall size. You can use the Percent Support Library by adding the following to your dependencies. ...
FrameLayout is designed to block out an area on the screen to display a single item. You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child, using the android:layout_gravity attribute. Generally, FrameLayout is ...
2.3 The CoordinatorLayout is a container somewhat similar to FrameLayout but with extra capabilities, it is called super-powered FrameLayout in the official documentation. By attaching a CoordinatorLayout.Behavior to a direct child of CoordinatorLayout, you’ll be able to intercept touch events, wi...
2.3-2.3.2 An enclosing CoordinatorLayout can be used to achieve Material Design Scrolling Effects when using inner layouts that support Nested Scrolling, such as NestedScrollView or RecyclerView. For this example: app:layout_scrollFlags="scroll|enterAlways" is used in the Toolbar pro...
One of the most used attribute for LinearLayout is the weight of its child views. Weight defines how much space a view will consume compared to other views within a LinearLayout. Weight is used when you want to give specific screen space to one component compared to other. Key Properties: wei...
Hierarchy - LinearLayout(horizontal) - ImageView - LinearLayout(vertical) - TextView - TextView Code LinearLayout rootView = new LinearLayout(context); rootView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); rootView.s...
Every single ViewGroup (e.g. LinearLayout, RelativeLayout, CoordinatorLayout, etc.) needs to store information about its children's properties. About the way its children are being laid out in the ViewGroup. This information is stored in objects of a wrapper class ViewGroup.LayoutParams. To include...

Page 1 of 1