Android基础#10: Layout经典布局--layout中的控件左右平均分布,使用LinearLayout实现

本文详细介绍如何使用LinearLayout实现控件的水平平均分配布局,并演示了三种不同的显示位置:顶部、居中和底部。通过调整属性android:gravity,可以轻松改变布局的位置。

    优雅的设计好你的布局-----箴言-----

内容简介:

在实际开发中,经常需要将控件进行水平平均分配,本篇介绍用LinearLayout来实现水平平均。

下面是一个典型的布局文件:

(1)水平平分,在顶部显示:

默认情况下,Layout是在父的layout的顶部。

效果图1:

代码如下:

<?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"
    >


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="左"></Button>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="中"></Button>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="右"></Button>


</LinearLayout>

 

(2)水平平分,在竖直居中显示:

只需要在layout中加上android:gravity="center_vertical",即可。

效果图2:

 

代码如下:

<?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:gravity="center_vertical"
    >


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="左"></Button>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="中"></Button>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="右"></Button>


</LinearLayout>

(3)水平平分,在竖直在底部显示:

只需要在layout中加上android:gravity="center_vertical",即可。

效果图如下:

代码如下:

<?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:gravity="bottom"
    >


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="左"></Button>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="中"></Button>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="右"></Button>


</LinearLayout>

 


说明:
android:orientation:水平还是垂直。
android:gravity:在布局中的顶部,居中,还是底部显示。

android:layout_width:控件宽度。
android:layout_height:控件高度。
android:layout_weight:控件所占权重,例如,3个全是1,说明三个控件的权重是一样的,就实现了平均分配。


 

数据集介绍:电力线目标检测数据集 一、基础信息 数据集名称:电力线目标检测数据集 图片数量: 训练集:2898张图片 验证集:263张图片 测试集:138张图片 总计:3299张图片 分类类别: 类别ID: 0(电力线) 标注格式: YOLO格式,包含对象标注信息,适用于目标检测任务。 数据格式:JPEG/PNG图片,来源于空中拍摄或监控视觉。 二、适用场景 电力设施监控与巡检: 数据集支持目标检测任务,帮助构建能够自动识别和定位电力线的AI模型,用于无人机或固定摄像头巡检,提升电力设施维护效率和安全性。 能源与公用事业管理: 集成至能源管理系统中,提供实时电力线检测功能,辅助进行风险 assessment 和预防性维护,优化能源分配。 计算机视觉算法研究: 支持目标检测技术在特定领域的应用研究,促进AI在能源和公用事业行业的创新与发展。 专业培训与教育: 数据集可用于电力行业培训课程,作为工程师和技术人员学习电力线检测与识别的重要资源。 三、数据集优势 标注精准可靠: 每张图片均经过专业标注,确保电力线对象的定位准确,适用于高精度模型训练。 数据多样性丰富: 包含多种环境下的电力线图片,如空中视角,覆盖不同场景条件,提升模型的泛化能力和鲁棒性。 任务适配性强: 标注格式兼容YOLO等主流深度学习框架,便于快速集成和模型开发,支持目标检测任务的直接应用。 实用价值突出: 专注于电力线检测,为智能电网、自动化巡检和能源设施监控提供关键数据支撑,具有较高的行业应用价值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

liranke

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值