Android五大布局

Context:上下文,表示这个方法是在哪一个Activity下被使用
 * RelativeLayout:相对布局,其内部的空间都是相对于其他空间,或布局本身存在的
 * xmlns:定义Android的路径,并赋值给默认的android,但这个android是可以进行修改的
 * 1.相对布局居中
 * android:layout_centerInParent="true"--整体居中
 * android:layout_centerHorizontal="true"--水平居中
 * android:layout_centerVertical="true"--垂直居中
 * 2.相对于其他控件的位置--某一个控件的id
 * android:layout_toRightOf="@+id/b1"--在b1的右边
 * android:layout_above="@+id/b1"--在b1上面
 * android:layout_toLeftOf="@+id/b1"--在b1左边
 * android:layout_below="@+id/b1"--在b1下面
 * 3.与某一个控件的某一个边界对齐--某一个控件id
 * android:layout_alignTop="@+id/b1"--与b1上对齐
 * android:layout_alignBottom="@+id/b1"--与b1下对齐
 * android:layout_alignLeft="@+id/b1"--与b1左对齐
 * android:layout_alignRight="@+id/b1"--与b1右对齐
 * 4.与屏幕的某一个边界对齐--boolean
 * android:layout_alignParentLeft="true"--与布局左对齐
 * android:layout_alignParentTop="true"--与布局上对齐
 * android:layout_alignParentRight="true"--与布局右对齐
 * android:layout_alignParentBottom="true"--与布局下对齐
 * 5.当前控件的某一边距离布局或者控件--50dp
 * android:layout_marginTop="50dp"
 * android:layout_marginLeft="50dp"
 * android:layout_marginRight="50dp"
 * android:layout_marginBottom="50dp"
 * android:layout_margin="50dp"
 * 如果这个控件的上下左右与其他控件有一定的位置关系,距离的是某一个控件
 * 如果这个控件是单独存在的,距离的是布局
 * 
 * LinearLayout:线性布局,布局中的子控件都是按照横线或者竖线的形式排列的
 * android:orientation="horizontal"-->设置线性布局的方向
 * horizontal:横线  vertical:竖线
 * Layout_weight:表示某一个控件在屏幕中所占的比例-->线性方向上的比例
 * 如果控件上的比例是1:1的话,则可以直接使用权重,而当控件的比例是1:多的话,横线就把控件的宽设置为0dp,竖线上就把控件的高设置为0dp
 * 
 * TableLayou:表格布局,布局中的子控件按照表格的方式排列
 * 1.默认直接子控件按照竖直的形势排列,宽默认充满-->竖向的LinearLayout
 * 2.含有TableRow,利用此标签包裹起来的控件,会成为一行-->横向的LinearLayout
 * 3.TableRow中的权重必须是宽为0dp,TableLayout中的权重必须使高为0dp
 * 
 * FrameLayout:框架布局,布局中的子控件,先写入的会被后写入的覆盖,
 * 
 * AbsoluteLayout:绝对布局,布局中的子控件,是根据X和Y坐标来确认位置,暂时被谷歌官方抛弃
 * 
 * Gravity:重力,表示的是一个控件内部的文字显示在这个控件内部的位置
 * 其中,例子:右下角,right|bottom
 * 
 * padding:距离,控件或者布局内部的内容距离边界的一个尺寸
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面给出每种布局的一个简单实例: 1. 线性布局(LinearLayout) ```xml <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello" android:textSize="20sp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="World" android:textSize="20sp" /> </LinearLayout> ``` 2. 相对布局(RelativeLayout) ```xml <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello" android:textSize="20sp" /> <TextView android:id="@+id/text2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="World" android:textSize="20sp" android:layout_below="@id/text1" android:layout_alignParentRight="true" /> </RelativeLayout> ``` 3. 帧布局(FrameLayout) ```xml <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/image1" android:scaleType="centerCrop" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello" android:textSize="20sp" android:layout_gravity="center" /> </FrameLayout> ``` 4. 表格布局(TableLayout) ```xml <TableLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TableRow> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Name" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter your name" /> </TableRow> <TableRow> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Age" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter your age" /> </TableRow> </TableLayout> ``` 5. 网格布局(GridLayout) ```xml <GridLayout android:layout_width="match_parent" android:layout_height="match_parent" android:rowCount="3" android:columnCount="3"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="1" android:textSize="20sp" android:layout_row="0" android:layout_column="0" android:layout_columnWeight="1" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="2" android:textSize="20sp" android:layout_row="0" android:layout_column="1" android:layout_columnWeight="1" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="3" android:textSize="20sp" android:layout_row="0" android:layout_column="2" android:layout_columnWeight="1" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="4" android:textSize="20sp" android:layout_row="1" android:layout_column="0" android:layout_columnWeight="1" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="5" android:textSize="20sp" android:layout_row="1" android:layout_column="1" android:layout_columnWeight="1" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="6" android:textSize="20sp" android:layout_row="1" android:layout_column="2" android:layout_columnWeight="1" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="7" android:textSize="20sp" android:layout_row="2" android:layout_column="0" android:layout_columnWeight="1" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="8" android:textSize="20sp" android:layout_row="2" android:layout_column="1" android:layout_columnWeight="1" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="9" android:textSize="20sp" android:layout_row="2" android:layout_column="2" android:layout_columnWeight="1" /> </GridLayout> ``` 以上是五种布局的简单实例,开发者可以根据具体需求进行修改和调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值