实现效果:
实现步骤:
创建3个输入框,1个按钮,1个显示验证码的图片
使用线性布局 [垂直排列]:
验证码和验证码图片,两个控件放在一行
由于垂直的线性布局特点是:控件独占一行
使用又写了一个线性布局[水平],存放验证码 输入框与图片
布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:padding="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@mipmap/user" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@mipmap/pass"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:drawableStart="@mipmap/code"/>
<ImageView
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:src="@drawable/default_code"/>
</LinearLayout>
<Button
android:layout_width="200dp"
android:layout_height="50dp"
android:text="登录"
android:layout_marginTop="50dp"
android:layout_gravity="center"/>
</LinearLayout>
drawableStart 设置输入框的图标:显示在左侧
图片资源:
以上传至文章