`
haking
  • 浏览: 262337 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

常见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有没有更新。

 

 

 

分享到:
评论

相关推荐

    LayoutParams类

    LayoutParams类描述

    Android LinearLayout.LayoutParams 使用方法

    1.LinearLayout.LayoutParams使用说明 2.在Java代码中利用LinearLayout.LayoutParams构建布局

    WindowManager.LayoutParams

    在此文档中列出了 所有WindowManager.LayoutParams的参数及详细信息

    LayoutParams

    LayoutParams

    windowManager.LayoutParams

    各参数内容描述~~

    WindowManager属性详解

    WindowManager属性详解:WindowManager.LayoutParams 是 WindowManager 接口的嵌套类;继承于 ViewGroup.LayoutParams 。 它的内容十分丰富。其实WindowManager.java的主要内容就是由这个类定义构成。

    android 自动换行layout

    自定义自动换行LinearLayout LayoutParams使用android.widget.LinearLayout.LayoutParams

    Android 柱状图

    LinearLayout.LayoutParams pm = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, 300); zxView = new ZXView(this, xlist, ylist, params); zxView.setLayoutParams(pm); layout.addView...

    布局组建layout

    ViewGroup是布局管理器(layout)及view容器的基类。ViewGroup中,还定义了一个嵌套类ViewGroup.LayoutParams。这个类定义了一个显示对象的位置、大小等属性,view通过LayoutParams中的这些属性值来告之父级,它们将...

    android - 交换控件(relativelayout)位置,LayoutParams与ObjectAnimator两种方法

    现需要交换两个控件...1、使用LayoutParams改变两个layout的属性,即其相对关系(below等),实现位置的交换,但是并没有交换的动画效果,是“瞬间”交换。 2、使用animation交换控件位置,实现了我需要的动画效果。

    inmobi广告jar包

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT); layout.addView(mAdView, params); // ...

    Android 仿蘑菇街列表弹出和瀑布流ScrollView+RelativeLayout实现

    RelativeLayout.LayoutParams layout_params = null; layout_params = new RelativeLayout.LayoutParams(width, height); // padding是控件的内容相对控件的边缘的边距. // margin是控件边缘相对父控件,或者其他...

    android.service.java

    View lay = LayoutInflater.from(this).inflate(R.layout.mylinearlayout, null);// 讲xml问价解析为视图对象 merchant = (TextView) lay.findViewById(R.id.merchant); number = (TextView) lay....

    仿QQ的头像选择弹出的对话框,酷似!

    View view = getLayoutInflater().inflate(R.layout.photo_choose_dialog, null); Dialog dialog = new Dialog(this, R.style.transparentFrameWindowStyle); dialog.setContentView(view, new LayoutParams...

    android顶部滑动导航

    import android.view.ViewGroup.LayoutParams; import android.view.animation.LinearInterpolator; import android.view.animation.TranslateAnimation; import android.widget.HorizontalScrollView; import ...

    谷歌开源的Android排版库 FlexboxLayout.zip

    FlexboxLayout.LayoutParams lp = (FlexboxLayout.LayoutParams) view.getLayoutParams(); lp.order = -1; lp.flexGrow = 2; view.setLayoutParams(lp);屏幕截图: 标签:谷歌 google 排版库

    Android View的六种移动方式

    自定义view的六种移动方式,通过使用offsetLeftAndRight(offsetX),setLayoutParams(layoutParams)等等,还可以控制view的滚动速度

    Android-SimpleLayout

    setContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); ImageView img = new ImageView(getApplication()); img.setImageResource(R.drawable.ic_launcher); ...

    瀑布流demo

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); addView(containerLayout, layoutParams);...

    代码动态设置view或布局的宽高

    然而这时候你一定要注意强制类型转换时的LayoutParams类型,因为android中存在3种LayoutParams,即RelativeLayout.LayoutParams、LinearLayout.LayoutParams、ViewGroup.LayoutParams,那么我们改用哪一个呢?...

Global site tag (gtag.js) - Google Analytics