RelativeLayoutis a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parentRelativeLayoutarea (such as aligned to the bottom, left or center).
ARelativeLayoutis a very powerful utility for designing a user interface because it can eliminate nested view groups and keep your layout hierarchy flat, which improves performance. If you find yourself using several nestedLinearLayoutgroups, you may be able to replace them with a singleRelativeLayout.
Positioning Views
RelativeLayoutlets child views specify their position relative to the parent view or to each other (specified by ID). So you can align two elements by right border, or make one below another, centered in the screen, centered left, and so on. 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 fromRelativeLayout.LayoutParams.
Some of the many layout properties available to views in aRelativeLayoutinclude:
android:layout_alignParentTop
If"true", makes the top edge of this view match the top edge of the parent.
android:layout_centerVertical
If"true", centers this child vertically within its parent.
android:layout_below
Positions the top edge of this view below the view specified with a resource ID.
android:layout_toRightOf
Positions the left edge of this view to the right of the view specified with a resource ID.
These are just a few examples. All layout attributes are documented atRelativeLayout.LayoutParams.
The value for each layout property is either a boolean to enable a layout position relative to the parentRelativeLayoutor an ID that references another view in the layout against which the view should be positioned.
In your XML layout, dependencies against other views in the layout can be declared in any order. For example, you can declare that "view1" be positioned below "view2" even if "view2" is the last view declared in the hierarchy. The example below demonstrates such a scenario.
Example
Each of the attributes that control the relative position of each view are emphasized.
For details about all the layout attributes available to each child view of aRelativeLayout, seeRelativeLayout.LayoutParams.
就爱阅读www.92to.com网友整理上传,为您提供最全的知识大全,期待您的分享,转载请注明出处。
来源: http://www.92to.com/bangong/2017/04-05/19986802.html