Android studio编写一个简单的登录界面

打印 上一主题 下一主题

主题 550|帖子 550|积分 1650

1首先先创建一个空的activity项目,接着设置本身的项目名称,勾选上lacuncher

创建成功后点开manifests把刚刚创建的文件名下面的<intent-filter>这一行全部删除



然后点开res,复制一张图片,右键drawable点击粘贴,这里放的是图片资源,用于放置登录头像

然后点开layout文件,开始编写我们的项目,右上角有三个选项分别为,展示代码,代码加效果,效果,这里我们选择代码加图片方便查看,当前为代码加效果,再点击一次还可以切换成上下。


然后我们将原来的androidx这一串更改为RelativeLayout

设置间隔边界的大小以及颜色



然后我们设置用户头像,并居中,编写如下代码,id是随便取的,但是需要记住,等下调节页面布局的时候需要用到

计划用户名和暗码表格,这里重叠了效果不太好


最后加入一个登录按钮,然后根据id调节一下位置

最后运行一下



  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     android:paddingVertical="15dp"
  8.     android:background="#e3e3e3"
  9.     tools:context=".SecondActivity">
  10.     <ImageButton
  11.         android:layout_width="70dp"
  12.         android:layout_height="70dp"
  13.         android:layout_centerHorizontal="true"
  14.         android:src="@drawable/img"
  15.         android:id="@+id/ivimg"
  16.         android:layout_marginTop="45dp"/>
  17.     <TableLayout
  18.         android:layout_width="match_parent"
  19.         android:layout_height="wrap_content"
  20.         android:layout_marginTop="15dp"
  21.         android:layout_below="@+id/ivimg"
  22.         android:id="@+id/table"
  23.         android:background="#fff"
  24.         android:layout_centerHorizontal="true"
  25.         android:stretchColumns="1"
  26.         >
  27.         <TableRow android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/row1" >
  28.             <TextView android:id="@+id/tvUser" android:layout_width="60dp"
  29.                 android:layout_height="wrap_content" android:textSize="18sp" android:text="用户"/>
  30.             <EditText android:layout_height="wrap_content" android:layout_width="match_parent"
  31.                 android:id="@+id/edUser"/>
  32.         </TableRow>
  33.         <TableRow android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/row2" >
  34.             <TextView android:id="@+id/tvPassword" android:layout_width="60dp"
  35.                 android:layout_height="wrap_content" android:textSize="18sp" android:text="密码"/>
  36.             <EditText android:layout_height="wrap_content" android:layout_width="match_parent"
  37.                 android:id="@+id/edPassword"
  38.                 android:inputType="textPassword"/>
  39.         </TableRow>
  40.     </TableLayout>
  41.     <Button
  42.         android:layout_width="120dp"
  43.         android:layout_height="wrap_content"
  44.         android:layout_centerHorizontal="true"
  45.         android:background="#a7157c"
  46.         android:textSize="20sp"
  47.         android:textColor="#fff"
  48.         android:text="登录"
  49.         android:id="@+id/btnLogin"
  50.         android:layout_below="@+id/table"
  51.         android:layout_marginTop="60dp"
  52.         />
  53. </RelativeLayout>
复制代码

 最后就完成了一个简单页面的创建


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

美食家大橙子

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表