常见Layout的LayoutParams总结

LayoutParams

java.lang.Object

<-- android.view.ViewGroup.LayoutParams

 

android:layout_height        

Specifies the basic height of the view. 
android:layout_width         

Specifies the basic width of the view.

 


MarginLayoutParams

java.lang.Object

<-- android.view.ViewGroup.LayoutParams

<-- android.view.ViewGroup.MarginLayoutParams

 

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

java.lang.Object

<-- android.view.ViewGroup.LayoutParams

<-- android.view.ViewGroup.MarginLayoutParams

<-- android.widget.FrameLayout.LayoutParams

 

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

java.lang.Object

<-- android.view.ViewGroup.LayoutParams

<-- android.view.ViewGroup.MarginLayoutParams

<-- android.widget.LinearLayout.LayoutParams

 

android:layout_gravity          

Standard gravity constant that a child can supply to its parent

android:layout_weight            

 

 

RelativeLayout

java.lang.Object

<-- 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

java.lang.Object

<-- android.view.ViewGroup.LayoutParams

<-- android.view.ViewGroup.MarginLayoutParams

<-- android.widget.LinearLayout.LayoutParams

<-- android.widget.TableLayout.LayoutParams

 

 

AbsoluteLayout

java.lang.Object

<-- android.view.ViewGroup.LayoutParams
<-- android.widget.AbsoluteLayout.LayoutParams

 

java.lang.Object 

<-- android.R.styleable

<-- public static final int[] AbsoluteLayout_Layout

 

android:layout_x
android:layout_y

 

Note: AbsoluteLayout is deprecated. Use other layouts instead.

 

 

 

总结

 

1. 界面的原点(0, 0)是除去status bar和title bar之后剩下的区域。 如果使用了全屏,不显示状态栏,不显示标题栏这样的主题后,区域的原点位置会相应改变。

 

2. FrameLayout的widget中使用类似android:layout_marginLeft="65px"这样的属性,一定要加上android:layout_gravity,否则margin无效。还要注意FrameLayout的android:layout_width和android:layout_height对layout_gravity的影响。

 

3. 使用布局属性一定要分清谁是parent,parent用的是什么layout,layout_width和layout_height的值。

 

4. 不同的布局属性也可以实现相同的功能。例如layout_gravity="center"和android:layout_centerInParent ="true"。

 

5. Eclipse的Android开发工具插件ADT里面有一个所见即所得的开发UI的功能。利用Graphical Layout可以预览的效果。但是,有时会遇到以下问题:

error!
UnsupportedOperationException: null

一般来说,这是因为所选择的Android版本不支持布局设置或者Android SDK不能很好的支持该layout的显示。可以尝试换其他Android版本或者看看该版本的SDK有没有更新。

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值