day0818-Android五大布局

本文详细介绍了Android应用开发中常用的布局系统,包括线性布局、相对布局、帧布局、表格布局等,通过实例展示了各布局的特点及使用方法,帮助开发者更好地理解和运用这些布局来构建复杂的UI界面。

一、LinearLayout线性布局:

1.android:orientation指定排列方向:

指定水平horizontal 或者竖直vertical

android:orientation="vertical"

2.长宽设置:

    android:layout_width="match_parent"
    android:layout_height="match_parent"

3.比重layout_gravity:

1)
- andriod:gravity和android:layout_gravity的区别:
andriod:gravity是用于指定文字在控件
范例:
小技巧:对于比重,如果是在水平上分占比重,那么就让组件宽度为0dp;如果是在竖直上分占比重,就让组件长度为0dp。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"/>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_weight="2">
            <Button
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
            <Button
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>

        </LinearLayout>

    </LinearLayout>
    <Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">
            <Button
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
            <Button
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
            <Button
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>

        </LinearLayout>
        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"/>

    </LinearLayout>


</LinearLayout>

结果:
这里写图片描述
2)weight用法:
<1>将宽度指定为0dp,由比重来决定宽度比重。
<2>当两个组件,一个组件仍将长度设为”wrap_content“,那么另一个weight设为1时,将使此组件占下剩下的所有空间。
<3>weightSum=”5”设定总重

4.margin***:

top.bottom.left,right 距离临近组件的距离

5.单位:

  • px:像素
  • dp:1英寸存在160px,那么1dp=1px,若存在320px,那么2px(即1英寸的像素数除以160):根据手机的不同而不同
  • sp:只用于文本的大小,但跟dp一样。
    android中一般用dp和sp。

二、RelativeLayout相对布局

1.相对父布局:

  • android:layout_alignParentLeft 和父布局的左边对齐
  • android:layout_alignParentRight 和父布局的右边对齐
  • android:layout_alignParentTop 和父布局的上边对齐
  • android:layout_alignParentBottom 和父布局的底部对齐
    这里写图片描述

2.与父布局中心对齐

  • android:layout_centerInParent 和父布局的中心对齐
  • android:layout_centerVertical 和父布局的中心垂直对齐
  • android:layout_centerHorizontal 和父布局的中心水平对齐

3.相对其他控件

  • android:layout_above=”@id/button” 位于另一个控件上方
  • android:layout_below=”@id/button” 位于另一个控件下方
  • android:layout_toLeftOf=”@id/button” 位于另一个控件左边
  • android:layout_toRightOf=”@id/button” 位于另一个控件右边

4.相对其他控件边缘位置

  • android:layout_alignLeft 左边缘对齐
  • android:layout_alignRight 右边缘对齐
  • android:layout_alignLeft 左边缘对齐
  • android:layout_alignTop 顶部边缘对齐
  • android:layout_alignButtom 底部边缘对齐
  • android:alignBaseLine 基准线对齐

三、FrameLayout帧布局:

android_visibility 值:可见,不可见,gone是不可见也不占位置。
一个个往上摞。

四、TableLayout表格布局:

1.每加入一个TableRow就表示在表格中添加了一行,然后在TableRow中每加入一个控件,就表示在该行中加入了一列。
2.TableRow中的控件时不能指定宽度的。
3.表格合并 android:layout_span=”2”让控件占据两列的空间。
4.宽度的解决:

  • android:stretchColumns 允许将某一列进行拉伸,以达到自动适应屏幕宽度的作用。即分配剩余空间。
    值为1:表示如果表格不能完全占满屏幕宽度,就拉伸第2列。注:指定0表示拉伸第一列,指定1表示拉伸第二列。,
  • android:shrinkColumns:自动收缩。
  • android: collapsecolumns:隐藏某一列

五、absolutLayout ,不推荐

android:layout_x
android:layout_y

附:

对于match:是填充剩余的控件。例如:
当线性布局中(垂直布局),先画按钮,在画一个match高度的ImagView时,按钮可以显示;
如若,先画match的ImageView再画按钮,按钮就无法显示了。

【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值