`
bolutes
  • 浏览: 869151 次
文章分类
社区版块
存档分类
最新评论

android 布局中的属性总结

 
阅读更多

第一类:属性值为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的引用名“@id/id-name”

android:layout_below 在某元素的下方

android:layout_above 在某元素的的上方

android:layout_toLeftOf 在某元素的左边

android:layout_toRightOf 在某元素的右边

android:layout_alignTop 本元素的上边缘和某元素的的上边缘对齐

android:layout_alignLeft 本元素的左边缘和某元素的的左边缘对齐

android:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐

android:layout_alignRight 本元素的右边缘和某元素的的右边缘对齐

第三类:属性值为具体的像素值,如30dip,40px

android:layout_marginBottom 离某元素底边缘的距离

android:layout_marginLeft 离某元素左边缘的距离

android:layout_marginRight 离某元素右边缘的距离

android:layout_marginTop 离某元素上边缘的距离

android:gravity 

android:gravity属性是对该view 内容的限定.比如一个button 上面的text. 你可以设置该text 在view的靠左,靠右等位置.以button为例,android:gravity="right"则button上面的文字靠右

android:layout_gravity

android:layout_gravity是用来设置该view相对与起父view 的位置.比如一个button 在linearlayout里,你想把该button放在靠左、靠右等位置就可以通过该属性设置.以button为例,android:layout_gravity="right"则button靠右

android:layout_alignParentRight

使当前控件的右端和父控件的右端对齐。这里属性值只能为true或false,默认false。

padding和margin的区别:

google的Android文档里的解释:

public static final int padding

Since: API Level 1

Sets the padding, in pixels, of all four edges. Padding is defined as space between the edges of the view and the view's content. A views size will include it's padding. If a background is provided, the padding will initially be set to that (0 if the drawable does not have padding). Explicitly setting a padding value will override the corresponding padding found in the background.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

Constant Value: 16842965 (0x010100d5)

再看margin,以marginBottom 举例

Android:layout_marginBottom

Since: API Level

Specifies extra space on the bottom side of this view. This space is outside this view's bounds.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_marginBottom.

Related Methods

setMargins(int,int,int,int)

所以padding是定义控件自己的内容和控件边缘之间的距离,padding有填充填料的意思,而margin是在说控件的四个边缘之外的距离,指的是和别的控件之间的距离,margin有边缘,页面留白的意思

借用一幅别人的图来说明

感觉android:gravity,android:padding是相对于空间自身而言的,而android:layout_gravity,android:layout_margin是控件相对于父控件或者是其他控件的,ndroid:layout_gravity是当前控件相对于父控件而android:margin当前控件四个边缘的距离,可以是父控件也可以是其他控件。

Weight:对应的设置为android:layout_weight。layout_weight 用于给一个线性布局中的诸多视图的重要度赋值。所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空间。若赋一个高于零的值,则将父视图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight值以及该值在当前屏幕布局的整体 layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。举个例子:比如说我们在水平方向上有一个文本标签和两个文本编辑元素。该文本标签并无指定layout_weight值,所以它将占据需要提供的最少空间。如果两个文本编辑元素每一个的 layout_weight值都设置为1,则两者平分在父视图布局剩余的宽度(因为我们声明这两者的重要度相等)。如果两个文本编辑元素其中第一个的 layout_weight值设置为1,而第二个的设置为2,则剩余空间的三分之二分给第一个,三分之一分给第二个(数值越小,重要度越高)。但是对于LinearLayout之间则以反比的形式显示在屏幕上(即数值越小,重要度越小)

分享到:
评论

相关推荐

    android布局属性大全(总结)

    android布局属性,在平时开发中不断总结的,很值得参考

    Android布局属性总结

    Android布局属性总结,总结了在Android开发中常用的所有布局的属性使用方法。

    android布局属性总结文档

    android最全的布局属性总结,各种Layout如linearlayout ,relativeLayout,frameLayout,各种widget属性说明

    android 布局属性大总结

    好的软件要配有好的布局,好的界面,有了这个布局大全让自己在布局上面有新的突破!

    Android页面布局总结

    android 中常用的几种布局方式:LinearLayout ( 线性布局 )、LinearLayout ( 线性布局 )、TableLayout ( 表格布局 ),及控件的各种属性

    Android中LinearLayout布局的常用属性总结

    主要介绍了Android中LinearLayout布局的常用属性总结,包括居中、重心、比例等线性布局中的基本设置,需要的朋友可以参考下

    Android 布局中的android:onClick的使用方法总结

    Android布局中的 android:onClick=“…”属性设置点击时从上下文中调用指定的方法。该属性值和要调用的方法名称完全一致。一般在Activity定义符合如下参数和返回值的函数并将方法名字符串指定为该属性值即可: ...

    RelativeLayout相对布局属性

    总结android中相对布局RelativeLayout的所有属性及使用方法。适合初级程序员

    android视频旋转相关知识总结

    当数据量较大时,在屏幕旋转时,一般都采用两种方式避免Activity从新... 如果不想让软件在横竖屏之间切换,最简单的办法就是在项目的 AndroidManifest.xml中找到你所指定的Activity中加上android:screenOrientation属性

    安卓课程设计外卖/网上商城(含报告)

    Google 给我们提供的一个专门用于底部导航的 View,菜单在xml布局使用,注意的就是 app:menu 属性,它指定了导航栏显示的页面菜单是怎样的。 2.掌握自定义布局。创建自定义布局的步骤:编写一个自定义xml布局,将这...

    Android代码-SuperTextView

    3.2.1、布局中使用 3.2.2、在代码中使用 3.2.3、属性介绍 4、 实现原理 4.1、需求分析 4.2、代码封装 4.3、总结 5、更新日志 1、功能描述 > SuperTextView是一个功能强大的View,可以满足日常大部分布局样式...

    Android中layout属性大全

    本文总结了Android中layout属性的含义与用法。分享给大家供大家参考。具体如下: 布局: AbsoluteLayout(绝对布局): xmlns:android=”http://scmemas.android.com/apk/res/android” style=”@…” android:...

    android开发资料大全

    最无私的Android资料(书籍+代码)分享[总结] Android中文帮助教程(非常合适新手入门) android程序编写及调试新手入门 大家一起学Android(Windows篇) android入门与提高必看指南 Android入门逆引手册 Android...

    Android自主学习项目报告(一).doc

    解决方案:不要在让transactions在其他的Activity生命周期函数提交,如onActivi tyResult()、onStart()和onResume() 自己在学习过程中总结的知识点 (3)Android体系结构和Android项目目录 Android是基于Linux内核...

    《Android应用开发》个人总结报告.doc

    要的布局(或者控件) ,在学习界面中,我发现Android为我们提供了很好的类似反射机制,通过Layout文件夹 下的配置文件,可以快速的形成界面,在配置文件可以设置属性或者样式都是很快捷方 便。对比较特殊的界面也可以...

    mar视频android源码

    关于mar所录制的视频所以例子源码,包括了android的基础知识例子,以及后面一个mp3播放器例子,共25个例子,包括activity的生命周期,layout下的布局文件属性等介绍.. 总结例子Mp3播放器等,有不懂加qq群74311864

    Android实现TextView中文字链接的4种方式介绍及代码

    当文字中出现URL、E-mail、电话号码等的时候,可以将TextView的android:autoLink属性设置为相应的的值,如 果是所有的类型都出来就是android:autoLink=”all”。当然也可以在java代码里 做,textView01....

    android群雄传

    7.3 Android布局动画 171 7.4 Interpolators(插值器) 171 7.5 自定义动画 172 7.6 Android 5.X SVG矢量动画机制 175 7.6.1 标签 175 7.6.2 SVG常用指令 176 7.6.3 SVG编辑器 177 7.6.4 Android中使用SVG ...

Global site tag (gtag.js) - Google Analytics