More often, you will use one of these constants to set the width or height: , is a better approach, because it helps ensure that your app will display properly across a variety of device screen sizes. The former returns the left, or X, coordinate of the rectangle representing the view.The accepted measurement types are defined in the Available Resources document. The latter returns the top, or Y, coordinate of the rectangle representing the view.In addition, several convenience methods are offered to avoid unnecessary computations, namely .These dimensions define the actual size of the view on screen, at drawing time and after layout.Padding can be set using the class provides a unique way to display the views you nest within it.
As you can see in figure 2, the parent view group defines layout parameters for each child view (including the child view group). Visualization of a view hierarchy with layout parameters associated with each view Note that every Layout Params subclass has its own syntax for setting values.Many Layout Params also include optional margins and borders.You can specify width and height with exact measurements, though you probably won't want to do this often.Tip: To debug your layout at runtime, use the Layout Inspector tool.Using Android's XML vocabulary, you can quickly design UI layouts and the screen elements they contain, in the same way you create web pages in HTML — with a series of nested elements.The Android framework gives you the flexibility to use either or both of these methods to build your app's UI.For example, you can declare your app's default layouts in XML, and then modify the layout at runtime.For example, here's an XML layout that uses a vertical directory, so it will properly compile.More information about the syntax for a layout XML file is available in the Layout Resources document.Each layout file must contain exactly one root element, which must be a View or View Group object.Once you've defined the root element, you can add additional layout objects or widgets as child elements to gradually build a View hierarchy that defines your layout.