关于LayoutParams

每一个布局均有一个叫LayoutParams的内部类,如:

LinearLayout.LayoutParams  RelativeLayout.LayoutParams  AbsoluteLayout.LayoutParams  TableLayout.LayoutParams  TableLayout.LayoutParams  FrameLayout.LayoutParams

此内部类用于指明某个view在其父元素中的位置,以linearLayout为例:

Per-child layout information associated with LinearLayout.

Standard gravity constant that a child supplies to its parent. Defines how the child view should be positioned, on both the X and Y axes, within its enclosing layout.

在LinearLayout中,只有2个xml属性:layout_gravity, layout_weight

但在RelativeLayout中,由于其涉及较多的位置选项,因此有多个xml属性:

Attribute Name Related Method Description
android:layout_above   Positions the bottom edge of this view above the given anchor view ID. 
android:layout_alignBaseline   Positions the baseline of this view on the baseline of the given anchor view ID. 
android:layout_alignBottom   Makes the bottom edge of this view match the bottom edge of the given anchor view ID. 
android:layout_alignEnd   Makes the end edge of this view match the end edge of the given anchor view ID. 
android:layout_alignLeft   Makes the left edge of this view match the left edge of the given anchor view ID. 
android:layout_alignParentBottom   If true, makes the bottom edge of this view match the bottom edge of the parent. 
android:layout_alignParentEnd   If true, makes the end edge of this view match the end edge of the parent. 
android:layout_alignParentLeft   If true, makes the left edge of this view match the left edge of the parent. 
android:layout_alignParentRight   If true, makes the right edge of this view match the right edge of the parent. 
android:layout_alignParentStart   If true, makes the start edge of this view match the start edge of the parent. 
android:layout_alignParentTop   If true, makes the top edge of this view match the top edge of the parent. 
android:layout_alignRight   Makes the right edge of this view match the right edge of the given anchor view ID. 
android:layout_alignStart   Makes the start edge of this view match the start edge of the given anchor view ID. 
android:layout_alignTop   Makes the top edge of this view match the top edge of the given anchor view ID. 
android:layout_alignWithParentIfMissing   If set to true, the parent will be used as the anchor when the anchor cannot be be found for layout_toLeftOf, layout_toRightOf, etc. 
android:layout_below   Positions the top edge of this view below the given anchor view ID. 
android:layout_centerHorizontal   If true, centers this child horizontally within its parent. 
android:layout_centerInParent   If true, centers this child horizontally and vertically within its parent. 
android:layout_centerVertical   If true, centers this child vertically within its parent. 
android:layout_toEndOf   Positions the start edge of this view to the end of the given anchor view ID. 
android:layout_toLeftOf   Positions the right edge of this view to the left of the given anchor view ID. 
android:layout_toRightOf   Positions the left edge of this view to the right of the given anchor view ID. 
android:layout_toStartOf   Positions the end edge of this view to the start of the given anchor view ID. 

总而言之,LayoutParams子类用于指定某个元素的位置信息。



转载于:https://www.cnblogs.com/jinhong-lu/p/4559509.html

你可能感兴趣的:(移动开发)