Android Studio相对布局与控件基本使用——制作登录界面

发布于:2024-07-11 ⋅ 阅读:(40) ⋅ 点赞:(0)

目录

一、工程目录文件介绍

AndroidMainfirst.xml:  

res:

MainActivity:

二、安卓APP启动过程

三、安卓布局控件

相对布局:

RelativeLayout中子控件常用属性:

1、相对于父控件

2、相对给定id控件

3、居中

四、常用控件

五、padding和margin

六、登录界面制作

1、展示

2、代码


一、工程目录文件介绍

AndroidMainfirst.xml:  

APP的配置

权限:网络访问权限,名片夹访问权限,相机访问权限

目标机器SDK版本:

APP的名字

APP的图标

配置第一个被加载,启动页面

res:

drawable:存放app程序要用到的一些图片

layout: 存放布局文件的文件夹,一般一个activity(安卓页面)对应一个布局

values: 存放一些参数,或者自定义控件的文件

MainActivity:

存放程序的文件夹,一般一个activity(安卓页面)对应一个程序

二、安卓APP启动过程

        Laucher->mainifirst->lauch标签的activity被加载->oncreat被调用->java关联xml布局页面->显示->等待用户触摸等操作

三、安卓布局控件

相对布局:

RelativeLayout中子控件常用属性:

1、相对于父控件
android:layout_alignParentTop      控件的顶部与父控件的顶部对齐;
android:layout_alignParentBottom  控件的底部与父控件的底部对齐;
android:layout_alignParentLeft      控件的左部与父控件的左部对齐;
android:layout_alignParentRight     控件的右部与父控件的右部对齐;
2、相对给定id控件
android:layout_above 控件的底部置于给定ID的控件之上;
android:layout_below     控件的底部置于给定ID的控件之下;
android:layout_toLeftOf    控件的右边缘与给定ID的控件左边缘对齐;
android:layout_toRightOf  控件的左边缘与给定ID的控件右边缘对齐;
android:layout_alignBaseline  控件的baseline与给定ID的baseline对齐;
android:layout_alignTop        控件的顶部边缘与给定ID的顶部边缘对齐;
android:layout_alignBottom   控件的底部边缘与给定ID的底部边缘对齐;
android:layout_alignLeft       控件的左边缘与给定ID的左边缘对齐;
android:layout_alignRight      控件的右边缘与给定ID的右边缘对齐;
3、居中
android:layout_centerHorizontal 水平居中;
android:layout_centerVertical    垂直居中;
android:layout_centerInParent  父控件的中央;

四、常用控件

基础控件之Button,TextView,EditText,ImageView在制作登录界面实践

五、padding和margin

六、登录界面制作

1、展示

2、代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#59b1ef"
    tools:context=".MainActivity">

    <ImageView
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:id="@+id/image1"
        android:src="@drawable/youla"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="70dp"
        />

    <RelativeLayout
        android:layout_width="400dp"
        android:layout_height="200dp"
        android:layout_centerInParent="true"
        android:background="#f1962c">

        <TextView
            android:id="@+id/user"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginTop="20dp"
            android:text="用户"
            android:textSize="30sp" />

        <EditText
            android:id="@+id/ed1"
            android:layout_width="310dp"
            android:layout_height="50dp"
            android:layout_marginTop="20dp"
            android:layout_toEndOf="@id/user"
            tools:ignore="SpeakableTextPresentCheck" />

        <TextView
            android:id="@+id/pass"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginTop="20dp"
            android:layout_below="@id/user"
            android:text="密码"
            android:textSize="30sp" />

        <EditText
            android:id="@+id/ed2"
            android:layout_width="310dp"
            android:layout_height="50dp"
            android:layout_below="@id/ed1"
            android:layout_marginTop="10dp"
            android:layout_toEndOf="@id/pass"
            tools:ignore="SpeakableTextPresentCheck" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn_denglu"
            android:text="登录"
            android:textSize="25sp"
            android:layout_below="@id/ed2"
            android:layout_marginTop="8dp"
            android:layout_centerHorizontal="true" />


    </RelativeLayout>

</RelativeLayout>