android中常用的布局管理器

android中常用的布局管理器,第1张

概述Android中的几种常用布局,主要介绍内容有:View视图 RelativeLayout  相对布局管理器    LinearLayout  线性布局管理器    FrameLayout  真布局管理器    TableLayout  表格布局管理器    GridLayout  网格

AndroID中的几种常用的布局,主要介绍内容有:

  VIEw视图

 

  relativeLayout    相对布局管理器

       linearLayout     线性布局管理器

       FrameLayout     真布局管理器

       tableLayout     表格布局管理器

       GrIDLayout     网格布局管理器

 

(1) VIEw在XML文件中的常用属性定义:

 

        layout_margin:指定该视图与周围视图之间的空白距离(包括上下左右),(可分别写成layout_margintop、layout_marginleft、layout_marginRight、layout_marginBottom)

   minWIDth:指定该视图的最小宽度

   minHeight:指定该视图得到最小高度

   padding:指定该视图的内边距。同样有paddingBottom、paddingtop、paddingleft、paddingRight属性

   visable:指定该视图的可视类型(visable 可见;invisible 不可见但是占位;gone 消失,不可见且不占位)

   layout_gravity:指定该视图与上级视图的对齐方式(left,right,top,bottom,center,center_horizontal,center_vertical)

      layout_wIDth、layout_height、background、ID等

    

      在代码中的常用设置方法说明:

  setLayoutParams:设置视图宽高,参数对象的构造函数可以设置视图的宽高,其中,有LayoutParams.MATCH_PARENT和LayoutParams.WRAP_CONTENT

  setBackgroundcolor:设置背景颜色

  setBackgroundDrawable:设置背景图片

  setBackgroundResourse:设置背景资源ID

  setpadding

       setVisability

(2)relativeLayout    相对布局管理器

          relativeLayout下级视图的位置是相对位置,得有具体的参照物才能确定最终位置。如果不设定下级视图的参照物,那么下级视图默认显示在relative内部的左上角。用于确定视图位置的           参照物可以是该视图的平级视图也可以是该视图的上级视图。

             androID:gravity      设置子组件的摆放方式

             androID:ignoreGra     设置该ID的组件不受gravity影响(需要ID)

          ---属性值为true或false

                   androID:layout_centerHrizontal 水平居中
                   androID:layout_centerVertical 垂直居中
                   androID:layout_centerInparent 相对于父元素完全居中
                   androID:layout_alignParentBottom 贴紧父元素的下边缘
                   androID:layout_alignParentleft 贴紧父元素的左边缘
                  androID:layout_alignParentRight 贴紧父元素的右边缘
                  androID:layout_alignParenttop 贴紧父元素的上边缘
                  androID:layout_alignWithParentIfMissing 如果对应的兄弟元素找不到的话就以父元素做参照物
        ---属性值为ID   (相对组件的位置)

                  androID:layout_below 在某元素的下方
                  androID:layout_above 在某元素的的上方
                  androID:layout_toleftOf 在某元素的左边
                  androID:layout_toRightOf 在某元素的右边                  androID:layout_aligntop 本元素的上边缘和某元素的的上边缘对齐
                  androID:layout_alignleft 本元素的左边缘和某元素的的左边缘对齐
                  androID:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐
                  androID:layout_alignRight 本元素的右边缘和某元素的的右边缘对齐       ---属性值为具体的像素值,如40dip,40px                androID:layout_marginBottom 离某元素底边缘的距离
                androID:layout_marginleft 离某元素左边缘的距离
                androID:layout_marginRight 离某元素右边缘的距离
                androID:layout_margintop 离某元素上边缘的距离 总结

以上是内存溢出为你收集整理的android中常用的布局管理器全部内容,希望文章能够帮你解决android中常用的布局管理器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1065308.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存