安卓的基本布局
相对布局管理器:在一个参考点的四周(上,下,左,右)布局的管理器,即位置都是相对的。
线性布局管理器:分为水平和垂直两种,垂直较为常用,垂直布局相和横格纸类似。
帧布局管理器(这个不常用):在帧布局管理中,每加入一个组件,都将创建一个空白的区域,通常称为帧,这些帧都会根据gravity属性执行自动对齐。默认情况下,帧布局从屏幕的左上角(0,0)坐标点开始布局,多个组件层叠排序,后面的组件覆盖前面的组件。
表格布局管理器和网格布局管理器较为类似,两者都呈格子布局。不过网格布局较为灵活。
登录界面的代码编写
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <!--第一行--> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="20dp" android:hint="@string/text1" android:drawableLeft="@mipmap/zhanghao" android:inputType="text" /> <!--第二行--> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="20dp" android:hint="@string/text2" android:drawableLeft="@mipmap/mima" android:inputType="textPassword" android:autofillHints="password" /> <!--第三行--> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/text3" android:textColor="#FFFFFF" android:background="#FF009688"/> <!--第四行--> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/text4" android:gravity="center_horizontal" android:paddingTop="20dp"/> </LinearLayout>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?