线性布局
- 一、线性布局
- 二、对齐方式
- 三、登录界面设计
- 四、备注
(学习笔记)
一、线性布局
- 布局:排列方式(在进行Android开发中,常常需要用到各种布局来进行UI的绘制)。
- 线性布局时Android最常见的一种布局方式,线性布局分为水平线性布局和垂直线性布局,通过android:orientation属性可以设置线性布局的方向。
垂直方向——
android:orientation:vertical
水平方向——
android:orientation:horizontal
==== (垂直方向)
==== (水平方向)
二、对齐方式
- 常用属性:android:gravity——设置控件内(子控件)的内容位置
- 常用居中对齐显示:
底端水平居中——
android:gravity="center_horizontal|bottom"
右侧垂直居中——
android:gravity="center_vertical|right"
三、登录界面设计
总布局是垂直的。
设置右间距——
android:layout_marginRight="30px"
登录界面xml——
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" xmlns:app="https://schemas.android.com/apk/res-auto" xmlns:tools="https://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" tools:context=".MainActivity"> <LinearLayout android:gravity="center" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_marginRight="30px" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名" /> <EditText android:id="@+id/editTextTextPersonName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:inputType="textPersonName" /> </LinearLayout> <LinearLayout android:gravity="center" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_marginRight="30px" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密 码" /> <EditText android:id="@+id/editTextTextPersonName2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:inputType="textPersonName" /> </LinearLayout> <LinearLayout android:gravity="center" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:layout_marginRight="90px" android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录" /> <Button android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="取消" /> </LinearLayout> </LinearLayout>
四、备注
should use @string resource警告的解决方法
(可不解决)
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/addevelopment/893645.html