linearlayout
主:三个:( orientation: linearLayout 的首要特性)
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
次:
比重:
android:layout_weight="1.0"
1.0表示占满空余空间 的比重
android:layout_width="fill_parent"
android:layout_height="fill_parent"
两个相对重力 :
android:layout_gravity="right" 表示在 容器(linearLayout)右对齐
android:gravity="center_vertical" 表示在 控件中的内容 (如edit Text 中的文本在 editText中 局中 )
android:layout_centerHorizontal="true" 局中 水平 方式
-----------------------------------------------------------------
TableRow
主:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns=”0″ 表示列0 可以根据表格内容拉申
android:stretchColumns=”0,1,2″ 表示列0,1,2 可以根据表格内容拉申
collapseColumns – 设置隐藏那些列,列ID从0开始,多个列的话用”,”分隔
stretchColumns – 设置自动伸展那些列,列ID从0开始,多个列的话用”,”分隔
shrinkColumns -设置自动收缩那些列,列ID从0开始,多个列的话用”,”分隔
可以用”*”来表示所有列,同一列可以同时设置为shrinkable和stretchable。
子:(多个行)
<TableRow>
...各控件 .. 平行列
</TableRow>
也可以在TableRow外面写控件 就不是经表格形式的,(但会横跨整行)
只可以设置 android:layout_height 横跨被强制
故,
<View
android:layout_height=”2dip”
android:background=”#FF909090″ />
就会变成了一条平拉的分割线
<TableRow>
<TextView
android:layout_column=”1″ 我是第二列
android:text=”打开…”
android:padding=”3dip” /> 元素内容与边界之间保留3dip的距离
<TextView
android:text=”Ctrl-O”
android:gravity=”right”
android:padding=”3dip” />
</TableRow>
就会自动空一列出来 与下面有第一列的长度对齐 从第二列开始放这个控件
android:singleLine="false"
------------------------------------------------------------------------------------------
通俗的理解 Padding 为内边框,Margin 为外边框
对应的属性为
android:layout_marginBottom="25dip"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:layout_marginRight="10dip"
android:paddingLeft="1dip"
android:paddingTop="1dip"
android:paddingRight="1dip"
android:paddingBottom="1dip"
如果左右上下都是相同的设置则可以直接设置
android:layout_margin="10dip"
android:padding="5dip"
-----------------------------------------------------------
// 相对于给定ID控件
android:layout_above 将该控件的底部置于给定ID的控件之上;
android:layout_below 将该控件的底部置于给定ID的控件之下;
android:layout_toLeftOf 将该控件的右边缘与给定ID的控件左边缘对齐;
android:layout_toRightOf 将该控件的左边缘与给定ID的控件右边缘对齐;
android:layout_alignBaseline 将该控件的baseline与给定ID的baseline对齐;
android:layout_alignTop 将该控件的顶部边缘与给定ID的顶部边缘对齐;
android:layout_alignBottom 将该控件的底部边缘与给定ID的底部边缘对齐;
android:layout_alignLeft 将该控件的左边缘与给定ID的左边缘对齐;
android:layout_alignRight 将该控件的右边缘与给定ID的右边缘对齐;
// 相对于父组件
android:layout_alignParentTop 如果为true,将该控件的顶部与其父控件的顶部对齐;
android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;
android:layout_alignParentLeft 如果为true,将该控件的左部与其父控件的左部对齐;
android:layout_alignParentRight 如果为true,将该控件的右部与其父控件的右部对齐;
// 居中
android:layout_centerHorizontal 如果为true,将该控件的置于水平居中;
android:layout_centerVertical 如果为true,将该控件的置于垂直居中;
android:layout_centerInParent 如果为true,将该控件的置于父控件的中央;
// 指定移动像素
android:layout_marginTop 上偏移的值;
android:layout_marginBottom 下偏移的值;
android:layout_marginLeft 左偏移的值;
android:layout_marginRight 右偏移的值;
example:
android:layout_below = "@id/***"
android:layout_alignBaseline = "@id/***"
android:layout_alignParentTop = true
android:layout_marginLeft = “10px”
----------------------------------------------------------
FrameLayout
几个 图片控件 ImageView
注: 每一次是把所有的图变成和 最大的那张图一样大,
故如果 最大的那张图没有在初始可见时,最后它变可见的时候就只能显示一部分,故为确保所有项都正确地呈现,可以调用setConsiderGoneChildrenWhenMeasuring()并向它传入true.
Android支持的长度单位。
为了使用户界面能够在现在和将来的显示器类型上正常显示,建议大家始终使用sp作为文字大小的单位,Android默认的字号也是用的sp。
将dip作为其他元素的单位,比如长度、高度。当然,也可以考虑使用矢量图形,而不是用位图。
dp是与密度无关,sp除了与密度无关外,还与scale无关。
如果屏幕密度为160,这时dp和sp和px是一样的。1dp=1sp=1px,但如果使用px作单位,如果屏幕大小不变(假设还是3.2寸),而屏幕密度变成了320。
那么原来TextView的宽度设成160px,在密度为320的3.2寸屏幕里看要比在密度为160的3.2寸屏幕上看短了一半。
但如果设置成160dp或160sp的话。系统会自动将width属性值设置成320px的。
也就是160 * 320 / 160。其中320 / 160可称为密度比例因子。也就是说,如果使用dp和sp,系统会根据屏幕密度的变化自动进行转换.