Android studio 使用线性布局写一个登陆界面的代码
时间: 2023-06-01 16:02:11 浏览: 195
以下是使用线性布局编写一个简单的登陆界面的代码,包含用户名和密码输入框,以及登陆按钮。
```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter username" />
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter password"
android:inputType="textPassword" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />
</LinearLayout>
```
在这个布局中,我们使用了一个垂直排列的线性布局,包含了一个用户名输入框、一个密码输入框以及一个登陆按钮。用户名和密码输入框使用了相同的布局参数,都是宽度为match_parent,高度为wrap_content。登陆按钮也是宽度为match_parent,高度为wrap_content,显示了一个“Login”的文本。
您可以将这个布局复制到您的Android Studio项目中,并使用它来构建一个简单的登陆界面。