• Android好看的动画欢迎界面(附有详细代码)


    首先来演示一下视频效果

    从视频效果中我们可以看到,这个欢迎界面的效果还是不错的,感兴趣的可以尝试一下,比较简单,下面会给出具体代码实现。

    main_activity.xml

    1. "1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. xmlns:app="http://schemas.android.com/apk/res-auto"
    4. xmlns:tools="http://schemas.android.com/tools"
    5. android:layout_width="match_parent"
    6. android:layout_height="match_parent"
    7. tools:context=".MainActivity"
    8. android:orientation="vertical"
    9. android:background="#1f1f1d">
    10. <RelativeLayout
    11. android:layout_width="match_parent"
    12. android:layout_height="wrap_content">
    13. <View
    14. android:id="@+id/first_line"
    15. android:layout_width="20dp"
    16. android:layout_height="50dp"
    17. android:layout_centerHorizontal="true"
    18. android:background="@color/white"/>
    19. <View
    20. android:id="@+id/second_line"
    21. android:layout_width="20dp"
    22. android:layout_height="100dp"
    23. android:layout_toRightOf="@+id/first_line"
    24. android:layout_marginLeft="8dp"
    25. android:background="#ff0000"/>
    26. <View
    27. android:id="@+id/third_line"
    28. android:layout_width="20dp"
    29. android:layout_height="250dp"
    30. android:layout_toRightOf="@+id/second_line"
    31. android:layout_marginLeft="8dp"
    32. android:background="@color/white"/>
    33. <View
    34. android:id="@+id/fourth_line"
    35. android:layout_width="20dp"
    36. android:layout_height="200dp"
    37. android:layout_toRightOf="@+id/third_line"
    38. android:layout_marginLeft="8dp"
    39. android:background="#ff0000"/>
    40. <View
    41. android:id="@+id/fifth_line"
    42. android:layout_width="20dp"
    43. android:layout_height="220dp"
    44. android:layout_toRightOf="@+id/fourth_line"
    45. android:layout_marginLeft="8dp"
    46. android:background="@color/teal_200"/>
    47. <View
    48. android:id="@+id/six_line"
    49. android:layout_width="20dp"
    50. android:layout_height="150dp"
    51. android:layout_toRightOf="@+id/fifth_line"
    52. android:layout_marginLeft="8dp"
    53. android:background="@color/white"/>
    54. RelativeLayout>
    55. <RelativeLayout
    56. android:layout_marginTop="50dp"
    57. android:layout_width="match_parent"
    58. android:layout_height="wrap_content">
    59. <TextView
    60. android:id="@+id/a"
    61. android:layout_width="wrap_content"
    62. android:layout_height="wrap_content"
    63. android:layout_centerHorizontal="true"
    64. android:text="智能基座"
    65. android:textColor="@color/white"
    66. android:textSize="60sp"
    67. android:textStyle="italic"/>
    68. RelativeLayout>
    69. <LinearLayout
    70. android:layout_width="match_parent"
    71. android:layout_height="match_parent">
    72. <RelativeLayout
    73. android:layout_width="match_parent"
    74. android:layout_height="wrap_content"
    75. android:layout_gravity="bottom">
    76. <TextView
    77. android:id="@+id/tagLine"
    78. android:layout_width="wrap_content"
    79. android:layout_height="wrap_content"
    80. android:layout_centerHorizontal="true"
    81. android:layout_marginBottom="50dp"
    82. android:text="Andorid Developer"
    83. android:textColor="#fff"
    84. android:textSize="24sp" />
    85. RelativeLayout>
    86. LinearLayout>
    87. LinearLayout>

    以上是xml文件的实现代码,总的来说还是比较简洁的,使用了LinearLayout,RelativeLayout布局方式,实现出来的静态效果如下所示

     想要实现动态效果,我们需要在MainActivity.java文件中去添加相关动画的配置,代码如下

    MainActivity.java

    1. package com.example.welcometest;
    2. import androidx.appcompat.app.AppCompatActivity;
    3. import android.content.Intent;
    4. import android.os.Bundle;
    5. import android.os.Handler;
    6. import android.view.View;
    7. import android.view.WindowManager;
    8. import android.view.animation.Animation;
    9. import android.view.animation.AnimationUtils;
    10. import android.widget.TextView;
    11. public class MainActivity extends AppCompatActivity {
    12. View first,second,third,forth,fifth,sixth;
    13. TextView a,tagline;
    14. Animation topAnimation,bottomAnimation,middleAnimation;
    15. @Override
    16. protected void onCreate(Bundle savedInstanceState) {
    17. super.onCreate(savedInstanceState);
    18. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    19. setContentView(R.layout.activity_main);
    20. topAnimation = AnimationUtils.loadAnimation(this,R.anim.top_ani);
    21. bottomAnimation = AnimationUtils.loadAnimation(this,R.anim.bottm_ani);
    22. middleAnimation = AnimationUtils.loadAnimation(this,R.anim.middle_ani);
    23. first = findViewById(R.id.first_line);
    24. second = findViewById(R.id.second_line);
    25. third = findViewById(R.id.third_line);
    26. forth = findViewById(R.id.fourth_line);
    27. fifth = findViewById(R.id.fifth_line);
    28. sixth = findViewById(R.id.six_line);
    29. a = findViewById(R.id.a);
    30. tagline = findViewById(R.id.tagLine);
    31. first.setAnimation(topAnimation);
    32. second.setAnimation(topAnimation);
    33. third.setAnimation(topAnimation);
    34. forth.setAnimation(topAnimation);
    35. fifth.setAnimation(topAnimation);
    36. sixth.setAnimation(topAnimation);
    37. a.setAnimation(middleAnimation);
    38. tagline.setAnimation(bottomAnimation);
    39. //跳转时间
    40. new Handler().postDelayed(new Runnable() {
    41. @Override
    42. public void run() {
    43. Intent intent = new Intent(MainActivity.this,MainActivity2.class);
    44. startActivity(intent);
    45. finish();
    46. }
    47. },3000);
    48. }
    49. }

    我们发现,MainActivity,java中有相关的配置文件,配置文件在这里给出

            1、首先第一步,我们需要在res目录下新建资源文件夹anim

             2、然后我们在这个目录下新建三个anim资源文件,用来配置动画效果

    top_ani.xml

    1. "1.0" encoding="utf-8"?>
    2. <set xmlns:android="http://schemas.android.com/apk/res/android">
    3. <translate
    4. android:duration = "1500"
    5. android:fromYDelta="-500%"
    6. android:fromXDelta="0%"/>
    7. <alpha
    8. android:fromAlpha="0.1"
    9. android:toAlpha="1.0"
    10. android:duration = "1500"
    11. />
    12. set>

    bottom_ani.xml

    1. "1.0" encoding="utf-8"?>
    2. <set xmlns:android="http://schemas.android.com/apk/res/android">
    3. <translate
    4. android:duration = "1500"
    5. android:fromYDelta="100%"
    6. android:fromXDelta="0%"/>
    7. <alpha
    8. android:fromAlpha="0.1"
    9. android:toAlpha="1.0"
    10. android:duration = "1500"
    11. />
    12. set>

    middle_ani.xml

    1. "1.0" encoding="utf-8"?>
    2. <set xmlns:android="http://schemas.android.com/apk/res/android">
    3. <translate
    4. android:duration = "1500"
    5. android:fromYDelta="0%"
    6. android:fromXDelta="-200%"/>
    7. <alpha
    8. android:fromAlpha="0.1"
    9. android:toAlpha="1.0"
    10. android:duration = "1500"
    11. />
    12. set>

    以上三个xml资源文件就是MainActivity.java中需要的族源文件。

    这样就可以成功运行了,大家要是想要效果比较好的话,记得去设置theme为NoActionBar

  • 相关阅读:
    ClickHouse架构原理-初探
    【ROS入门】机器人系统仿真——相关组件以及URDF集成Rviz
    探索ClickHouse——连接Kafka和Clickhouse
    day12-内核与文件系统衔接流程
    Linux系统中查看NextJS程序的CPU、内存占用情况
    Flutter打包iOS过程中pod访问github失败
    Java 变量之变量数据类型
    C语言基础知识点(九)数据类型溢出
    VUE中的异步组件
    第二十二章 : Docker 部署 MySQL8
  • 原文地址:https://blog.csdn.net/m0_58941767/article/details/126407024