常见Layout的LayoutParams总结

来源:互联网 发布:中南大学大数据专业 编辑:程序博客网 时间:2024/06/14 01:20
参考:
Android MarginLeft与MarginStart的区别
http://blog.csdn.net/zhufuing/article/details/40181815

常见Layout的LayoutParams总结

http://haking.iteye.com/blog/1182334

LayoutParams

// <-- android.view.ViewGroup.LayoutParamspublic static class LayoutParams {    public static final int MATCH_PARENT = -1;    public static final int WRAP_CONTENT = -2;    public int width;    public int height;}// android:layout_height// Specifies the basic height of the view.// android:layout_width// Specifies the basic width of the view.

MarginLayoutParams

//支持margin的View的布局,继承了LayoutParams// <-- android.view.ViewGroup.LayoutParams// <-- android.view.ViewGroup.MarginLayoutParamspublic static class MarginLayoutParams extends ViewGroup.LayoutParams {    public int leftMargin;    public int topMargin;    public int rightMargin;    public int bottomMargin;    //默认相当于leftMargin,用在RTL布局中    private int startMargin = DEFAULT_MARGIN_RELATIVE;    //默认相当于rightMargin,用在RTL布局中    private int endMargin = DEFAULT_MARGIN_RELATIVE;}// android:layout_marginBottom// Specifies extra space on the bottom side of this view.// android:layout_marginLeft// Specifies extra space on the left side of this view.// android:layout_marginRight// Specifies extra space on the right side of this view.// android:layout_marginTop// Specifies extra space on the top side of this view.

FrameLayout.LayoutParams

// <-- android.view.ViewGroup.LayoutParams// <-- android.view.ViewGroup.MarginLayoutParams// <-- android.widget.FrameLayout.LayoutParamspublic static class LayoutParams extends MarginLayoutParams {    public int gravity = UNSPECIFIED_GRAVITY;   //也就是Gravity.TOP | Gravity.START    public LayoutParams(int width, int height, int gravity) {        super(width, height);        this.gravity = gravity;    }}// android:layout_gravity            // Standard gravity constant that a child can supply to its parent// 注意区别android:gravity, 这个属性是android.view.Gravity,// FrameLayout.LayoutParams, LinearLayout.LayoutParams和各种常见的View都有android:gravity ;注意RelativeLayout.LayoutParams没有这个属性。

LinearLayout.LayoutParams

// <-- android.view.ViewGroup.LayoutParams// <-- android.view.ViewGroup.MarginLayoutParams// <-- android.widget.LinearLayout.LayoutParamspublic static class LayoutParams extends ViewGroup.MarginLayoutParams {    //非0表示可以让View撑大    public float weight;    /**     * Gravity for the view associated with these LayoutParams.     *     * @see android.view.Gravity     */    @ViewDebug.ExportedProperty(category = "layout", mapping = {        @ViewDebug.IntToString(from =  -1,                       to = "NONE"),        @ViewDebug.IntToString(from = Gravity.NO_GRAVITY,        to = "NONE"),        @ViewDebug.IntToString(from = Gravity.TOP,               to = "TOP"),        @ViewDebug.IntToString(from = Gravity.BOTTOM,            to = "BOTTOM"),        @ViewDebug.IntToString(from = Gravity.LEFT,              to = "LEFT"),        @ViewDebug.IntToString(from = Gravity.RIGHT,             to = "RIGHT"),        @ViewDebug.IntToString(from = Gravity.START,            to = "START"),        @ViewDebug.IntToString(from = Gravity.END,             to = "END"),        @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL,   to = "CENTER_VERTICAL"),        @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL,     to = "FILL_VERTICAL"),        @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"),        @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL,   to = "FILL_HORIZONTAL"),        @ViewDebug.IntToString(from = Gravity.CENTER,            to = "CENTER"),        @ViewDebug.IntToString(from = Gravity.FILL,              to = "FILL")    })    public int gravity = -1;    public LayoutParams(int width, int height, float weight) {        super(width, height);        this.weight = weight;    }}// android:layout_gravity          // Standard gravity constant that a child can supply to its parent// android:layout_weight      

RelativeLayout

// <-- android.view.ViewGroup.LayoutParams// <-- android.view.ViewGroup.MarginLayoutParams// <-- android.widget.RelativeLayout.LayoutParams // 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_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_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_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_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_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.

TableLayout
<-- android.view.ViewGroup.LayoutParams
<-- android.view.ViewGroup.MarginLayoutParams
<-- android.widget.LinearLayout.LayoutParams
<-- android.widget.TableLayout.LayoutParams

0 0
原创粉丝点击