Android常用布局

<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="50dp" android:layout_height="wrap_content" android:text="姓名:" /> <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> <Button android:layout_width="60dp" android:layout_height="wrap_content" android:text="提交" /> </LinearLayout>
左 中 右
左右 长度固定
设置中间的 android:layout_weight="1" 表示,左右填充完后,剩余的由中间填充

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="60dp" android:layout_height="wrap_content" android:text="消息:" /> <EditText android:id="@+id/txtMsg" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="60dp" android:layout_height="wrap_content" android:text="定时" /> <TimePicker android:id="@+id/txtWaringTime" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="60dp" android:layout_height="wrap_content" android:text="图片" /> <ImageView android:id="@+id/imageView1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/leaf" /> <ImageButton android:id="@+id/imageButton1" android:layout_width="80dp" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="60dp" android:layout_height="wrap_content" android:text="创建时间" /> <EditText android:id="@+id/txtAddTime" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="60dp" android:layout_height="wrap_content" android:text="最近执行" /> <EditText android:id="@+id/txtLastActTime" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="60dp" android:layout_height="wrap_content" android:text="最近提醒" /> <EditText android:id="@+id/txtLastNotifyTime" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="60dp" android:layout_height="wrap_content" android:text="GUID" /> <EditText android:id="@+id/txtGID" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="60dp" android:layout_height="wrap_content" android:text="今天忽略" /> <EditText android:id="@+id/txtLastIgnoreTime" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="60dp" android:layout_height="wrap_content" android:text="属性" /> <CheckBox android:id="@+id/chkInUse" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="启用" /> <CheckBox android:id="@+id/chkUseNotifyServer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="使用提醒服务" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="horizontal" > <Button android:id="@+id/btnSetIgnore" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="今天忽略" /> <Button android:id="@+id/btnSave" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="保存记录" /> <Button android:id="@+id/btnDel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="删除" /> <Button android:id="@+id/btnBack" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="退出 " /> </LinearLayout> </LinearLayout> </ScrollView>
带滚动条的布局,ScrollView直接包含元素只允许一个,但是非直接包含元素可以多个
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
2011-08-26 网站整合QQ登录