当前位置:   article > 正文

Android studio编写一个简单的登录界面_andriod studio 模拟手机登录界面前端代码

andriod studio 模拟手机登录界面前端代码

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>

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/454945
推荐阅读
相关标签
  

闽ICP备14008679号