界面代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E6E8FA"
tools:context=".MainActivity">
<ImageView
android:id="@+id/image"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:src="@drawable/pic"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
<LinearLayout
android:id="@+id/lt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/image"
android:background="#ffffff"
android:layout_marginTop="15dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:paddingLeft="10dp"
android:text="账号:"/>
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="@null"
android:letterSpacing="0.1"
android:padding="10dp"
android:lines="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lt"
android:background="#ffffff"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:paddingLeft="10dp"
android:text="密码:"/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:inputType="textPassword"
android:background="@null"
android:letterSpacing="0.1"
android:padding="10dp"
android:lines="1"/>
</LinearLayout>
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ll"
android:background="#3c8dc4"
android:layout_marginTop="40dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#ffffff"
android:text="登陆"/>
</RelativeLayout>
主程序代码:(只写了界面)
package com.example.helloworld;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
结果: