• Android超级好看的动态登陆界面(附有详细代码)


    首先先演示一下动态的效果

    QQ视频20220819164103

    从视频效果中,看到这个动态的登陆界面还是比较好看的,下面开始介绍如何制作这个动态的登陆界面。

    一、首先书写静态页面

    activity_mian.xml

    1. "1.0" encoding="utf-8"?>
    2. <androidx.constraintlayout.motion.widget.MotionLayout
    3. xmlns:android="http://schemas.android.com/apk/res/android"
    4. xmlns:app="http://schemas.android.com/apk/res-auto"
    5. xmlns:tools="http://schemas.android.com/tools"
    6. android:layout_width="match_parent"
    7. android:layout_height="match_parent"
    8. app:layoutDescription="@xml/motion_scene_splash"
    9. tools:context=".MainActivity"
    10. tools:ignore="MissingConstraints">
    11. <ImageView
    12. android:id="@+id/imgView_logo"
    13. android:layout_width="130dp"
    14. android:layout_height="130dp"
    15. android:layout_marginTop="80dp"
    16. android:scaleType="centerInside"
    17. android:src="@drawable/icon"
    18. app:layout_constraintEnd_toEndOf="parent"
    19. app:layout_constraintStart_toStartOf="parent"
    20. app:layout_constraintTop_toTopOf="parent" />
    21. <ImageView
    22. android:id="@+id/imgView_logo_rays"
    23. android:layout_width="130dp"
    24. android:layout_height="130dp"
    25. android:layout_marginTop="80dp"
    26. android:rotation="0"
    27. android:scaleType="centerInside"
    28. android:src="@drawable/icon2"
    29. app:layout_constraintEnd_toEndOf="parent"
    30. app:layout_constraintStart_toStartOf="parent"
    31. app:layout_constraintTop_toTopOf="parent" />
    32. <ImageView
    33. android:id="@+id/imgView_cloudLeft"
    34. android:layout_width="130dp"
    35. android:layout_height="130dp"
    36. android:layout_marginTop="16dp"
    37. android:scaleType="centerInside"
    38. android:src="@drawable/cloud"
    39. app:layout_constraintTop_toTopOf="parent"
    40. app:tint="@color/lightGrey" />
    41. <ImageView
    42. android:id="@+id/imgView_cloudRight"
    43. android:layout_width="130dp"
    44. android:layout_height="130dp"
    45. android:layout_marginTop="100dp"
    46. app:layout_constraintEnd_toEndOf="parent"
    47. app:layout_constraintTop_toTopOf="parent"
    48. android:scaleType="centerInside"
    49. android:src="@drawable/cloud"
    50. app:tint="@color/lightGrey"
    51. />
    52. <LinearLayout
    53. android:id="@+id/linlay_inputs"
    54. android:layout_width="match_parent"
    55. android:layout_height="wrap_content"
    56. android:layout_marginStart="30dp"
    57. android:layout_marginLeft="30dp"
    58. android:layout_marginEnd="30dp"
    59. android:layout_marginRight="30dp"
    60. android:gravity="center"
    61. android:layout_marginTop="10dp"
    62. android:orientation="vertical"
    63. app:layout_constraintEnd_toEndOf="parent"
    64. app:layout_constraintStart_toStartOf="parent"
    65. app:layout_constraintTop_toBottomOf="@+id/imgView_cloudRight">
    66. <TextView
    67. android:layout_width="wrap_content"
    68. android:layout_height="wrap_content"
    69. android:fontFamily="sans-serif-medium"
    70. android:text="Welcome Back"
    71. android:textColor="@color/textHeadline"
    72. android:textSize="20sp" />
    73. <TextView
    74. android:layout_width="wrap_content"
    75. android:layout_height="wrap_content"
    76. android:fontFamily="sans-serif"
    77. android:text="Sign in to continue"
    78. android:textColor="@color/textDescription"
    79. android:textSize="14sp" />
    80. <EditText
    81. android:layout_width="match_parent"
    82. android:layout_height="wrap_content"
    83. android:layout_marginTop="30dp"
    84. android:background="@drawable/edittext_bg"
    85. android:drawableStart="@drawable/custom_email_icon"
    86. android:drawablePadding="16dp"
    87. android:hint="Email"
    88. android:inputType="textEmailAddress"
    89. android:padding="16dp"
    90. android:textSize="14sp" />
    91. <EditText
    92. android:layout_width="match_parent"
    93. android:layout_height="wrap_content"
    94. android:layout_marginTop="20dp"
    95. android:background="@drawable/edittext_bg"
    96. android:drawableStart="@drawable/custom_lock_icon"
    97. android:drawableEnd="@drawable/ic_baseline_visibility_24"
    98. android:drawableRight="@drawable/ic_baseline_visibility_24"
    99. android:drawablePadding="16dp"
    100. android:hint="Password"
    101. android:inputType="textPassword"
    102. android:padding="16dp"
    103. android:textSize="14sp" />
    104. <Button
    105. android:layout_width="match_parent"
    106. android:layout_height="wrap_content"
    107. android:layout_marginTop="30dp"
    108. android:background="@drawable/button_bg"
    109. android:text="Login"
    110. android:textColor="@color/white" />
    111. LinearLayout>
    112. <TextView
    113. android:id="@+id/tv_forgotPassword"
    114. android:layout_width="wrap_content"
    115. android:layout_height="wrap_content"
    116. android:layout_marginTop="10dp"
    117. android:layout_marginEnd="30dp"
    118. android:layout_marginRight="30dp"
    119. android:text="Forgot Password?"
    120. android:textColor="@color/textDescription"
    121. android:textSize="13sp"
    122. app:layout_constraintEnd_toEndOf="parent"
    123. app:layout_constraintTop_toBottomOf="@id/linlay_inputs" />
    124. <TextView
    125. android:id="@+id/tv_register"
    126. android:layout_width="wrap_content"
    127. android:layout_height="wrap_content"
    128. android:text="Don't have an account?Register Here"
    129. android:textColor="@color/textHeadline"
    130. android:textSize="13sp"
    131. android:gravity="center"
    132. android:layout_marginBottom="30dp"
    133. app:layout_constraintEnd_toEndOf="parent"
    134. app:layout_constraintStart_toStartOf="parent"
    135. app:layout_constraintBottom_toBottomOf="parent"
    136. />
    137. androidx.constraintlayout.motion.widget.MotionLayout>

    这里有一点值得说一下,我们使用MotionLayout这个布局来实现动画效果,这个布局平时不太常见,它其实是属于ConstraintLayout的子类,所以它是一种布局类型,但是它能够为布局属性添加动画效果,是开发者实现动画效果的另一个新的选择。

    目前所实现的静态效果如下:

     接下来会通过资源文件来实现动态效果

    二、实现动态效果

    1、在res目录下新建xml文件资源目录

     2、在xml目录下新建xml资源文件(motion_scene_splash.xml)

    1. "1.0" encoding="utf-8"?>
    2. <MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    3. xmlns:motion="http://schemas.android.com/apk/res-auto">
    4. <Transition
    5. motion:autoTransition="animateToEnd"
    6. motion:constraintSetEnd="@layout/activity_login"
    7. motion:constraintSetStart="@layout/activity_splash"
    8. motion:duration="5000">
    9. <KeyFrameSet>
    10. <KeyPosition
    11. motion:framePosition="65"
    12. motion:keyPositionType="deltaRelative"
    13. motion:motionTarget="@+id/imgView_logo"
    14. motion:percentX="0"
    15. motion:percentY="0" />
    16. <KeyPosition
    17. motion:framePosition="65"
    18. motion:keyPositionType="deltaRelative"
    19. motion:motionTarget="@+id/imgView_logo_rays"
    20. motion:percentX="0"
    21. motion:percentY="0" />
    22. <KeyPosition
    23. motion:framePosition="75"
    24. motion:keyPositionType="deltaRelative"
    25. motion:motionTarget="@+id/imgView_logo"
    26. motion:percentX="1"
    27. motion:percentY="1" />
    28. <KeyPosition
    29. motion:framePosition="75"
    30. motion:keyPositionType="deltaRelative"
    31. motion:motionTarget="@+id/imgView_logo_rays"
    32. motion:percentX="1"
    33. motion:percentY="1" />
    34. <KeyAttribute
    35. android:rotation="0"
    36. motion:framePosition="0"
    37. motion:motionTarget="@+id/imgView_logo_rays" />
    38. <KeyAttribute
    39. android:rotation="180"
    40. motion:framePosition="85"
    41. motion:motionTarget="@+id/imgView_logo_rays" />
    42. <KeyPosition
    43. motion:framePosition="75"
    44. motion:keyPositionType="deltaRelative"
    45. motion:motionTarget="@+id/imgView_cloudLeft"
    46. motion:percentX="0"
    47. motion:percentY="0" />
    48. <KeyPosition
    49. motion:framePosition="75"
    50. motion:keyPositionType="deltaRelative"
    51. motion:motionTarget="@+id/imgView_cloudRight"
    52. motion:percentX="0"
    53. motion:percentY="0" />
    54. <KeyPosition
    55. motion:framePosition="85"
    56. motion:keyPositionType="deltaRelative"
    57. motion:motionTarget="@+id/imgView_cloudLeft"
    58. motion:percentX="1"
    59. motion:percentY="1" />
    60. <KeyPosition
    61. motion:framePosition="85"
    62. motion:keyPositionType="deltaRelative"
    63. motion:motionTarget="@+id/imgView_cloudRight"
    64. motion:percentX="1"
    65. motion:percentY="1" />
    66. <KeyAttribute
    67. motion:motionTarget="@+id/linlay_inputs"
    68. android:alpha="0"
    69. motion:framePosition="75"/>
    70. <KeyAttribute
    71. motion:motionTarget="@+id/linlay_inputs"
    72. android:alpha="1"
    73. motion:framePosition="85"/>
    74. <KeyAttribute
    75. motion:motionTarget="@+id/tv_forgotPassword"
    76. android:alpha="0"
    77. motion:framePosition="75"/>
    78. <KeyAttribute
    79. motion:motionTarget="@+id/tv_forgotPassword"
    80. android:alpha="1"
    81. motion:framePosition="85"/>
    82. <KeyPosition
    83. motion:framePosition="75"
    84. motion:percentY="0"
    85. motion:percentX="0"
    86. motion:motionTarget="@+id/tv_register"/>
    87. <KeyPosition
    88. motion:framePosition="85"
    89. motion:percentY="1"
    90. motion:percentX="1"
    91. motion:motionTarget="@+id/tv_register"/>
    92. KeyFrameSet>
    93. Transition>
    94. MotionScene>

    3、需要用到的全部资源文件

    activity_login.xml

    1. "1.0" encoding="utf-8"?>
    2. <androidx.constraintlayout.widget.ConstraintLayout
    3. xmlns:android="http://schemas.android.com/apk/res/android"
    4. xmlns:app="http://schemas.android.com/apk/res-auto"
    5. xmlns:tools="http://schemas.android.com/tools"
    6. android:layout_width="match_parent"
    7. android:layout_height="match_parent"
    8. tools:context=".MainActivity"
    9. tools:ignore="MissingConstraints">
    10. <ImageView
    11. android:id="@+id/imgView_logo"
    12. android:layout_width="130dp"
    13. android:layout_height="130dp"
    14. android:layout_marginTop="80dp"
    15. android:scaleType="centerInside"
    16. android:src="@drawable/icon"
    17. app:layout_constraintEnd_toEndOf="parent"
    18. app:layout_constraintStart_toStartOf="parent"
    19. app:layout_constraintTop_toTopOf="parent" />
    20. <ImageView
    21. android:id="@+id/imgView_logo_rays"
    22. android:layout_width="130dp"
    23. android:layout_height="130dp"
    24. android:layout_marginTop="80dp"
    25. android:rotation="0"
    26. android:scaleType="centerInside"
    27. android:src="@drawable/icon2"
    28. app:layout_constraintEnd_toEndOf="parent"
    29. app:layout_constraintStart_toStartOf="parent"
    30. app:layout_constraintTop_toTopOf="parent" />
    31. <ImageView
    32. android:id="@+id/imgView_cloudLeft"
    33. android:layout_width="130dp"
    34. android:layout_height="130dp"
    35. android:layout_marginTop="16dp"
    36. android:scaleType="centerInside"
    37. android:src="@drawable/cloud"
    38. app:layout_constraintTop_toTopOf="parent"
    39. app:tint="@color/lightGrey" />
    40. <ImageView
    41. android:id="@+id/imgView_cloudRight"
    42. android:layout_width="130dp"
    43. android:layout_height="130dp"
    44. android:layout_marginTop="100dp"
    45. app:layout_constraintEnd_toEndOf="parent"
    46. app:layout_constraintTop_toTopOf="parent"
    47. android:scaleType="centerInside"
    48. android:src="@drawable/cloud"
    49. app:tint="@color/lightGrey"
    50. />
    51. <LinearLayout
    52. android:id="@+id/linlay_inputs"
    53. android:layout_width="match_parent"
    54. android:layout_height="wrap_content"
    55. android:layout_marginStart="30dp"
    56. android:layout_marginLeft="30dp"
    57. android:layout_marginEnd="30dp"
    58. android:layout_marginRight="30dp"
    59. android:gravity="center"
    60. android:layout_marginTop="10dp"
    61. android:orientation="vertical"
    62. app:layout_constraintEnd_toEndOf="parent"
    63. app:layout_constraintStart_toStartOf="parent"
    64. app:layout_constraintTop_toBottomOf="@+id/imgView_cloudRight">
    65. <TextView
    66. android:layout_width="wrap_content"
    67. android:layout_height="wrap_content"
    68. android:fontFamily="sans-serif-medium"
    69. android:text="Welcome Back"
    70. android:textColor="@color/textHeadline"
    71. android:textSize="20sp" />
    72. <TextView
    73. android:layout_width="wrap_content"
    74. android:layout_height="wrap_content"
    75. android:fontFamily="sans-serif"
    76. android:text="Sign in to continue"
    77. android:textColor="@color/textDescription"
    78. android:textSize="14sp" />
    79. <EditText
    80. android:layout_width="match_parent"
    81. android:layout_height="wrap_content"
    82. android:layout_marginTop="30dp"
    83. android:background="@drawable/edittext_bg"
    84. android:drawableStart="@drawable/ic_baseline_email_24"
    85. android:drawableLeft="@drawable/ic_baseline_email_24"
    86. android:drawablePadding="16dp"
    87. android:hint="Email"
    88. android:inputType="textEmailAddress"
    89. android:padding="16dp"
    90. android:textSize="14sp" />
    91. <EditText
    92. android:layout_width="match_parent"
    93. android:layout_height="wrap_content"
    94. android:layout_marginTop="20dp"
    95. android:background="@drawable/edittext_bg"
    96. android:drawableStart="@drawable/ic_baseline_lock_24"
    97. android:drawableLeft="@drawable/ic_baseline_lock_24"
    98. android:drawableEnd="@drawable/ic_baseline_visibility_24"
    99. android:drawableRight="@drawable/ic_baseline_visibility_24"
    100. android:drawablePadding="16dp"
    101. android:hint="Password"
    102. android:inputType="textPassword"
    103. android:padding="16dp"
    104. android:textSize="14sp" />
    105. <Button
    106. android:layout_width="match_parent"
    107. android:layout_height="wrap_content"
    108. android:layout_marginTop="30dp"
    109. android:background="@drawable/button_bg"
    110. android:text="Login"
    111. android:textColor="@color/white" />
    112. LinearLayout>
    113. <TextView
    114. android:id="@+id/tv_forgotPassword"
    115. android:layout_width="wrap_content"
    116. android:layout_height="wrap_content"
    117. android:layout_marginTop="10dp"
    118. android:layout_marginEnd="30dp"
    119. android:layout_marginRight="30dp"
    120. android:text="Forgot Password?"
    121. android:textColor="@color/textDescription"
    122. android:textSize="13sp"
    123. app:layout_constraintEnd_toEndOf="parent"
    124. app:layout_constraintTop_toBottomOf="@id/linlay_inputs" />
    125. <TextView
    126. android:id="@+id/tv_register"
    127. android:layout_width="wrap_content"
    128. android:layout_height="wrap_content"
    129. android:text="Don't have an account?Register Here"
    130. android:textColor="@color/textHeadline"
    131. android:textSize="13sp"
    132. android:gravity="center"
    133. android:layout_marginBottom="30dp"
    134. app:layout_constraintEnd_toEndOf="parent"
    135. app:layout_constraintStart_toStartOf="parent"
    136. app:layout_constraintBottom_toBottomOf="parent"
    137. />
    138. androidx.constraintlayout.widget.ConstraintLayout>

    activity_splash.xml

    1. "1.0" encoding="utf-8"?>
    2. <androidx.constraintlayout.widget.ConstraintLayout
    3. xmlns:android="http://schemas.android.com/apk/res/android"
    4. xmlns:app="http://schemas.android.com/apk/res-auto"
    5. xmlns:tools="http://schemas.android.com/tools"
    6. android:layout_width="match_parent"
    7. android:layout_height="match_parent"
    8. tools:context=".MainActivity"
    9. tools:ignore="MissingConstraints">
    10. <ImageView
    11. android:id="@+id/imgView_logo"
    12. android:layout_width="130dp"
    13. android:layout_height="130dp"
    14. android:layout_marginTop="80dp"
    15. android:scaleType="centerInside"
    16. android:src="@drawable/icon"
    17. app:layout_constraintEnd_toEndOf="parent"
    18. app:layout_constraintStart_toStartOf="parent"
    19. app:layout_constraintTop_toTopOf="parent" />
    20. <ImageView
    21. android:id="@+id/imgView_logo_rays"
    22. android:layout_width="130dp"
    23. android:layout_height="130dp"
    24. android:layout_marginTop="80dp"
    25. android:rotation="0"
    26. android:scaleType="centerInside"
    27. android:src="@drawable/icon2"
    28. app:layout_constraintEnd_toEndOf="parent"
    29. app:layout_constraintStart_toStartOf="parent"
    30. app:layout_constraintTop_toTopOf="parent" />
    31. <ImageView
    32. android:id="@+id/imgView_cloudLeft"
    33. android:layout_width="130dp"
    34. android:layout_height="130dp"
    35. android:layout_marginTop="16dp"
    36. android:scaleType="centerInside"
    37. android:src="@drawable/cloud"
    38. app:layout_constraintTop_toTopOf="parent"
    39. app:tint="@color/lightGrey" />
    40. <ImageView
    41. android:id="@+id/imgView_cloudRight"
    42. android:layout_width="130dp"
    43. android:layout_height="130dp"
    44. android:layout_marginTop="100dp"
    45. app:layout_constraintEnd_toEndOf="parent"
    46. app:layout_constraintTop_toTopOf="parent"
    47. android:scaleType="centerInside"
    48. android:src="@drawable/cloud"
    49. app:tint="@color/lightGrey"
    50. />
    51. <LinearLayout
    52. android:id="@+id/linlay_inputs"
    53. android:layout_width="match_parent"
    54. android:layout_height="wrap_content"
    55. android:layout_marginStart="30dp"
    56. android:layout_marginLeft="30dp"
    57. android:layout_marginEnd="30dp"
    58. android:layout_marginRight="30dp"
    59. android:gravity="center"
    60. android:layout_marginTop="10dp"
    61. android:orientation="vertical"
    62. app:layout_constraintEnd_toEndOf="parent"
    63. app:layout_constraintStart_toStartOf="parent"
    64. app:layout_constraintTop_toBottomOf="@+id/imgView_cloudRight">
    65. <TextView
    66. android:layout_width="wrap_content"
    67. android:layout_height="wrap_content"
    68. android:fontFamily="sans-serif-medium"
    69. android:text="Welcome Back"
    70. android:textColor="@color/textHeadline"
    71. android:textSize="20sp" />
    72. <TextView
    73. android:layout_width="wrap_content"
    74. android:layout_height="wrap_content"
    75. android:fontFamily="sans-serif"
    76. android:text="Sign in to continue"
    77. android:textColor="@color/textDescription"
    78. android:textSize="14sp" />
    79. <EditText
    80. android:layout_width="match_parent"
    81. android:layout_height="wrap_content"
    82. android:layout_marginTop="30dp"
    83. android:background="@drawable/edittext_bg"
    84. android:drawableStart="@drawable/ic_baseline_email_24"
    85. android:drawableLeft="@drawable/ic_baseline_email_24"
    86. android:drawablePadding="16dp"
    87. android:hint="Email"
    88. android:inputType="textEmailAddress"
    89. android:padding="16dp"
    90. android:textSize="14sp" />
    91. <EditText
    92. android:layout_width="match_parent"
    93. android:layout_height="wrap_content"
    94. android:layout_marginTop="20dp"
    95. android:background="@drawable/edittext_bg"
    96. android:drawableStart="@drawable/ic_baseline_lock_24"
    97. android:drawableLeft="@drawable/ic_baseline_lock_24"
    98. android:drawableEnd="@drawable/ic_baseline_visibility_24"
    99. android:drawableRight="@drawable/ic_baseline_visibility_24"
    100. android:drawablePadding="16dp"
    101. android:hint="Password"
    102. android:inputType="textPassword"
    103. android:padding="16dp"
    104. android:textSize="14sp" />
    105. <Button
    106. android:layout_width="match_parent"
    107. android:layout_height="wrap_content"
    108. android:layout_marginTop="30dp"
    109. android:background="@drawable/button_bg"
    110. android:text="Login"
    111. android:textColor="@color/white" />
    112. LinearLayout>
    113. <TextView
    114. android:id="@+id/tv_forgotPassword"
    115. android:layout_width="wrap_content"
    116. android:layout_height="wrap_content"
    117. android:layout_marginTop="10dp"
    118. android:layout_marginEnd="30dp"
    119. android:layout_marginRight="30dp"
    120. android:text="Forgot Password?"
    121. android:textColor="@color/textDescription"
    122. android:textSize="13sp"
    123. app:layout_constraintEnd_toEndOf="parent"
    124. app:layout_constraintTop_toBottomOf="@id/linlay_inputs" />
    125. <TextView
    126. android:id="@+id/tv_register"
    127. android:layout_width="wrap_content"
    128. android:layout_height="wrap_content"
    129. android:text="Don't have an account?Register Here"
    130. android:textColor="@color/textHeadline"
    131. android:textSize="13sp"
    132. android:gravity="center"
    133. android:layout_marginBottom="30dp"
    134. app:layout_constraintEnd_toEndOf="parent"
    135. app:layout_constraintStart_toStartOf="parent"
    136. app:layout_constraintBottom_toBottomOf="parent"
    137. />
    138. androidx.constraintlayout.widget.ConstraintLayout>

    button_bg.xml (按钮背景)

    1. "1.0" encoding="utf-8"?>
    2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:shape="rectangle">
    4. <solid android:color="@color/colorPrimary" />
    5. <corners android:radius="10dp" />
    6. shape>

            给按钮设置了颜色属性和圆角属性,让按钮更加好看圆润。

    edittext_bg.xml(输入框背景)

    1. "1.0" encoding="utf-8"?>
    2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:shape="rectangle">
    4. <solid android:color="@color/lightGrey" />
    5. <corners android:radius="10dp" />
    6. shape>

    用到的图片资源如下:

     想要项目源码的可以收藏点赞,然后私信我即可!!!,私信必回!!!

  • 相关阅读:
    EFCore学习笔记(2)——实体类型
    [C++随想录] 优先级队列
    Redis高级
    CSS选择器
    基于MS16F3211芯片的触摸控制灯的状态变化和亮度控制(11.16)
    计算机毕业设计node+vue基于微信小程序的乐团团购系统的设计与实现
    斐波那契数列 IV
    【lwip】10-ICMP协议&源码分析
    软件测试面试常常遇到的6大“套路”!
    SpringBoot SpringBoot 开发实用篇 4 数据层解决方案 4.10 MongoDB 基础操作
  • 原文地址:https://blog.csdn.net/m0_58941767/article/details/126427805