美食家大橙子 发表于 2024-6-13 21:40:56

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

1首先先创建一个空的activity项目,接着设置本身的项目名称,勾选上lacuncher
https://img-blog.csdnimg.cn/direct/b9c6c4c9c3e14ebaba7bb7c2be9a51cc.pnghttps://img-blog.csdnimg.cn/direct/268713433f934bb28ac99714b67e5d67.png
创建成功后点开manifests把刚刚创建的文件名下面的<intent-filter>这一行全部删除
https://img-blog.csdnimg.cn/direct/f219f2f8a52e49bea0ae2d7772932c57.png

然后点开res,复制一张图片,右键drawable点击粘贴,这里放的是图片资源,用于放置登录头像
https://img-blog.csdnimg.cn/direct/91a5c95de23945c1a30635ddd1348284.png
然后点开layout文件,开始编写我们的项目,右上角有三个选项分别为,展示代码,代码加效果,效果,这里我们选择代码加图片方便查看,当前为代码加效果,再点击一次还可以切换成上下。
https://img-blog.csdnimg.cn/direct/42c40876b05b4d6b81042c42d6b2b675.png

然后我们将原来的androidx这一串更改为RelativeLayout
设置间隔边界的大小以及颜色
https://img-blog.csdnimg.cn/direct/9228c095c9bc4d07a98a1f0d3f84b789.png


然后我们设置用户头像,并居中,编写如下代码,id是随便取的,但是需要记住,等下调节页面布局的时候需要用到
https://img-blog.csdnimg.cn/direct/fbb8be5f3f514b4f9cbf55df825c3575.png
计划用户名和暗码表格,这里重叠了效果不太好
https://img-blog.csdnimg.cn/direct/c9de50cdc0b14d4eb1058e91d62bc86a.png

最后加入一个登录按钮,然后根据id调节一下位置
https://img-blog.csdnimg.cn/direct/fbbb1b820da14786bdb1b7cd0e24a258.png
最后运行一下
https://img-blog.csdnimg.cn/direct/552e4fac1439448793f44c03c7918671.png


<?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:paddingVertical="15dp"
    android:background="#e3e3e3"
    tools:context=".SecondActivity">

    <ImageButton
      android:layout_width="70dp"
      android:layout_height="70dp"
      android:layout_centerHorizontal="true"
      android:src="@drawable/img"
      android:id="@+id/ivimg"
      android:layout_marginTop="45dp"/>
    <TableLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="15dp"
      android:layout_below="@+id/ivimg"
      android:id="@+id/table"
      android:background="#fff"
      android:layout_centerHorizontal="true"
      android:stretchColumns="1"
      >
      <TableRow android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/row1" >
            <TextView android:id="@+id/tvUser" android:layout_width="60dp"
                android:layout_height="wrap_content" android:textSize="18sp" android:text="用户"/>
            <EditText android:layout_height="wrap_content" android:layout_width="match_parent"
                android:id="@+id/edUser"/>
      </TableRow>

      <TableRow android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/row2" >
            <TextView android:id="@+id/tvPassword" android:layout_width="60dp"
                android:layout_height="wrap_content" android:textSize="18sp" android:text="密码"/>
            <EditText android:layout_height="wrap_content" android:layout_width="match_parent"
                android:id="@+id/edPassword"
                android:inputType="textPassword"/>
      </TableRow>
    </TableLayout>
    <Button
      android:layout_width="120dp"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:background="#a7157c"
      android:textSize="20sp"
      android:textColor="#fff"
      android:text="登录"
      android:id="@+id/btnLogin"
      android:layout_below="@+id/table"
      android:layout_marginTop="60dp"
      />



</RelativeLayout>
 最后就完成了一个简单页面的创建


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Android studio编写一个简单的登录界面