【Android】01---界面布局

文章目录一、View视图二、常见布局0.布局的通用属性1.线性布局 (水平/垂直方向排列)2.相对布局(通过相对定位排列)3.帧布局(开辟空白区域,帧力的控件(层)叠加)4.表格布局(表格形式排列)5.约束布局(可视化的方式编写布局)提示:以下是本篇文章正文内容,下面案例可供参考一、View视图所有UI元素都是通过View和ViewGroup构建的。二、常见布局0.布局的通用属性属性名称功能描述android:id设置布局的标识android:layout_wi
摘要由CSDN通过智能技术生成


提示:以下是本篇文章正文内容,下面案例可供参考

一、View视图

所有UI元素都是通过View和ViewGroup构建的。

在这里插入图片描述

二、常见布局

0.布局的通用属性

属性名称 功能描述
android:id 设置布局的标识
android:layout_width 设置布局的宽度
android:layout_width 设置布局的宽度
android:layout_heigh 设置布局的高度
android:background 设置布局的背景
android:layout_margin 设置当前布局与屏幕编辑或与周围控件的距离
android:padding 设置当前布局与该布局中控件的距离

1.线性布局 (水平/垂直方向排列)

LinearLayout

控件属性 功能描述
android:id 属性
android:layout_width
android:layout_height
android:background 背景颜色
android:orientation=“horizontal” 水平
android:orientation=“vertical” 垂直
android:layout_marginRight 右外边距
android:layout_marginLeft 左外边距
android:layout_marginTop 上外边距
android:layout_marginBottom 下外边距
android:padding 内边距 (与控件的边距)
android:layout_weight=“1” 权重

当控件使用权重属性式,布局宽度属性通常设置为0dp


2.相对布局(通过相对定位排列)

          **RelativeLayout**
控件属性 功能描述
android:layout_centerInParent 设置当前控件位于父布局的中央位置
android:layout_centerVerical 设置当前控件位于父布局的垂直居中位置
android:layout_centerHorizontal 设置当前控件位于父布局的水平居中位置
android:layout_above 设置当前控件位于某控件上方
android:layout_below 设置当前控件位于某控件下方
android:layout_toLeftOf 设置当前控件位于某控件左侧
android:layout_toRightOf 设置当前控件位于某控件右侧
android:layout_alignParentTop 设置当前控件是否与父控件顶端对齐
android:layout_alignParentLeft 设置当前控件是否与父控件左对齐
android:layout_alignParentRight 设置当前控件是否与父控件右对齐
android:layout_alignParentBotttom 设置当前控件是否与父控件底端对齐
android:layout_aligbTop 设置当前控件的上边界与某控件的上边界对齐
android:layout_aligbBottom 设置当前控件的下边界与某控件的下边界对齐
android:layout_aligbLeft 设置当前控件的左边界与某控件的左边界对齐
android:layout_aligbRight 设置当前控件的右边界与某控件的右边界对齐

3.帧布局(开辟空白区域,帧力的控件(层)叠加)

FrameLayout

android:foregroundGravity="left"

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 创建一个新的Android Studio项目,并在activity_main.xml中打开设计视图。 2. 将LinearLayout拖放到屏幕上,并在属性检查器中设置以下属性: orientation:vertical(垂直方向) gravity:center(居中对齐) padding:16dp(内边距) 3. 在LinearLayout中添加一个TextView,用于显示应用程序名称或欢迎消息。 4. 接下来,使用两个EditText小部件添加一个LinearLayout,用于输入用户名和密码。为了使它们看起来更漂亮,可以使用drawable文件夹中的几个图标。 5. 紧接着,添加一个Button,用于提交登录或注册信息。可以使用selector文件夹中的几个不同状态的按钮,如pressed和focused。 6. 最后,添加一个TextView链接到注册页面,并在LinearLayout中设置gravity属性以居中对齐。 完成后,您的用户登录注册界面应该如此: ``` <LinearLayout android:orientation="vertical" android:gravity="center" android:padding="16dp" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="MyApp" android:textSize="24sp" android:textStyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <LinearLayout android:orientation="vertical" android:layout_marginTop="24dp" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:hint="Username" android:drawableLeft="@drawable/ic_person_outline_black_24dp" android:layout_width="match_parent" android:layout_height="wrap_content"/> <EditText android:hint="Password" android:drawableLeft="@drawable/ic_lock_outline_black_24dp" android:inputType="textPassword" android:layout_marginTop="16dp" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> <Button android:text="Login" android:textColor="#fff" android:background="@drawable/btn_bg" android:layout_marginTop="24dp" android:layout_width="match_parent" android:layout_height="wrap_content"/> <TextView android:text="Don't have an account? Register" android:textColor="@color/colorPrimaryDark" android:layout_marginTop="24dp" android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值