您的位置:首页 > 移动开发 > Android开发

好记性不如烂笔杆-android学习笔记<四> 布局用控件简单介绍

2012-11-20 16:11 465 查看
9,//LinearLayout
<!--
LinearLayout:线性布局
android:id -为控件指定相应的ID
android:text -指定控件当中显示的文字,需要注意的是,尽量使用string.xml
android:gravity ——指定控件的基本位置,比如说居中,居右等位置
android:textSize ——指定控件当中字体的大小
android:background ——指定控件所使用的背景色,RGB命名法
android:width ——指定空间的宽度
android:height ——指定控件的高度
android:padding* ——指定控件的内边距,控件当中内容距离边距的位置
android:sigleLine ——如果设置为真的话,则将控件的内容在同一行当中进行显示
android:layout_weight ——权重
-->
//设置了权重为何无效果???? 需要将每个textView的宽和高都设置为填充父类,这样设置权重时就有效了
//同时使用TableLayout和LinearLayout时,需要设置相同的权重,才能同时显示两个控件,否则会被覆盖

<TextView
android:id="@+id/firstText"
android:text="@string/firsttext"
android:gravity="center_vertical"
android:textSize="35pt"
android:background="#aa0000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:paddingTop="20dip"
android:paddingRight="30dip"
android:paddingBottom="40dip"
android:layout_weight="1"
android:singleLine="true" />


10,//TableLayout

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="2" >
<TableRow >
<TextView
android:text="@string/row1_column0"
android:padding="3dip"
android:background="#aa0000"/>
<TextView
android:text="@string/row1_column1"
android:padding="3dip"
android:background="#00aa00"/>
<TextView
android:text="@string/row1_column2"
android:padding="3dip"
android:background="#0000aa" />
</TableRow>
<TableRow >
<TextView
android:text="@string/row2_column0"
android:padding="3dip"
android:background="#aa0000" />
<TextView
android:text="@string/row2_column1"
android:padding="3dip"
android:background="#00aa00" />
<TextView
android:text="@string/row2_column2"
android:padding="3dip"
android:background="#0000aa"/>
</TableRow>
</TableLayout>


11,//RelativeLayout

android:layout_above 将该控件至于给定ID控件之上
android:layout_below 将该控件至于给定ID控件之下
android:layout_toLeftOf 将该控件至于给定ID控件左侧
android:layout_toRightOf 将该控件至于给定ID控件的右侧

android:layout_alignBaseline 将该控件的baseline和指定ID控件的baseline对齐
android:layout_alignBottom 将该控件的底部边缘与给定ID控件的底部边缘对齐
android:layout_alignLeft 将该控件的左边缘与指定ID控件的左边缘对齐
android:layout_alignRight 将该控件的有边缘与指定ID控件的右边缘对齐
android:layout_alignTop 将给定控件的顶部边缘与给定ID控件的顶部对齐

android:layout_alignParentBottom 如果为true,将该控件的底部和父控件的底部对齐
android:layout_alignParentLeft 如果为true,将该控件的左边与父控件的左边对齐
android:layout_alignParentRight 如果为true,将该控件的右边与父控件的右边对齐
android:layout_alignParentTop 如果为true,将控件的顶部与父控件的顶部对齐

android:layout_centerHorizontal 如果值为true,该控件被至于水平方向中央
android:layout_centerInParent 如果值为true,该控件被至于父控件水平方向和垂直方向中央
android:layout_centerVertical 如果值为true,该控件将被至于垂直方向的中央


//layout_marginLeft 整个按钮距离左边内容的距离
//layout_paddingLeft 按钮上内容距离左边界

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10px" >

<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/typehere" />
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label"/>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:text="@string/okButton"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="@string/cancelButton" />
</RelativeLayout>


12,//ScrollView,页面自动滚动
13,//FrameLayout
<1>,最简单,在屏幕上保留空间,之后填充单独对象
<2>,所有元素都在屏幕左上角
<3>,不能为子元素指定位置
14,//AbsoluteLayout
建议不使用,不同的设备显示不同,需要指出确切的X,Y坐标位置
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: