Giter VIP home page Giter VIP logo

weatheranimationdemo's Introduction

WeatherAnimationDemo

模仿墨迹下雪效果

  • 在布局中直接通过自定义 SurfaceView 来绘制提高效率

      <?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:id="@+id/activity_main"
      		android:layout_width="match_parent"
      		android:layout_height="match_parent">
    
      		<com.kit.weather.animation.view.SceneSurfaceView
      				android:id="@+id/sceneSurfaceView"
      				android:layout_width="match_parent"
      				android:layout_height="match_parent" />
    
      </RelativeLayout>
    
  • 通过配置文件来控制雪花降落速度、位置

weather_scene_slight_snow_day.xml
  • SnowFall.java
    protected SnowFall(Context context) {
         super(context);
         // 设置是否使用抗锯齿功能,会消耗较大资源,绘制图形速度会变慢
         paint.setAntiAlias(false);
         // 如果该项设置为true,则图像在动画进行中会滤掉对Bitmap图像的优化操作,加快显示速度,本设置项依赖于dither和xfermode的设置
         paint.setFilterBitmap(true);
         // 设定是否使用图像抖动处理,会使绘制出来的图片颜色更加平滑和饱满,图像更加清晰
         paint.setDither(true);
         try {
             listXMLData = SaxService.getInstance().readXML(context, "weather_scene_slight_snow_day.xml");
         } catch (Exception e) {
             e.printStackTrace();
         }
         getViewSize(context);
         loadRainImage(context);
         addRandomRain();
     }
    
    private void snowDown(ActorInfo snow) {
         // 雪花的落出屏幕后又让它从顶上下落
         if (snow.getX() > screenWidth || snow.getY() > screenHeiht) {
             snow.setY(0);
             snow.setX(random.nextFloat() * screenWidth);
         }
         snow.setX(snow.getX() + snow.getOffset());// 下落飘的偏移量
         snow.setY(snow.getY() + snow.getSpeed());// 下落的速度
     }

weatheranimationdemo's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.