winter is coming...

Related tags

UI/UX SnowingView
Overview

SnowingView

winter is coming...

介绍

一个看起来还不错的下雪动画。

功能&&实现

  1. 使用 Matrix 产生随机大小、透明度的雪花
  2. 使用 HandlerThread 来计算雪花的下一个位置
  3. 使用加速度传感器判断用户在 X 轴的倾斜方向,使雪花产生左右飘动的效果

缺点&改进

  1. 还未用 LeakCanary 检测是否有内存泄漏的情况
  2. 暂时还不支持 wrap_content
  3. 可能会采用 SurfaceView 来绘制提高效率

实际效果

SnowingView效果

使用(如果有人想用的话)

Step1

在布局中添加 SnowingView

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    >
    
  <info.hellovass.snowingview.widgets.SnowingView
      android:id="@+id/snowing_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:visibility="gone"
      app:src="@drawable/ic_snowflake"
      />

  <Switch
      android:id="@+id/sw_snowing"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:text="winter is coming..."
      android:textColor="@android:color/white"
      android:textSize="16sp"
      />
      
</FrameLayout>

Step2

在 Activity 中,调用 SnowingView 的 startFall() 或者 stopFall() 方法。

public class SampleActivity extends AppCompatActivity {

  private SnowingView mSnowingView;

  private Switch mSwitch;

  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);

    mSwitch = (Switch) findViewById(R.id.sw_snowing);
    mSnowingView = (SnowingView) findViewById(R.id.snowing_view);

    mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
      @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

        if (isChecked) {
          mSnowingView.startFall();  // 开始下雪
        } else {
          mSnowingView.stopFall(); // 停止下雪
        }
      }
    });
  }
}

参考

You might also like...
Owner
陈 轲
陈 轲
Movie Time Android App (Winter 2022)

Movie Time Android App (Winter 2022) Overview Movie time is an app for Android written in Kotlin for tracking movies that the user has watched and for

Alima Roman 2 May 13, 2022
Under the Hood is a flexible and powerful Android debug view library. It uses a modular template system that can be easily extended to your needs, although coming with many useful elements built-in.

Under the Hood - Android App Debug View Library Under the Hood is a flexible and powerful Android debug view library. It uses a modular template syste

Patrick Favre-Bulle 217 Nov 25, 2022
A powerful Minecraft Server Software coming from the future

Mirai A powerful Minecraft Server Software coming from the future Mirai is ❗ under heavy development ❗ and contributions are welcome! Features 30% fas

Etil 354 Dec 30, 2022
ZeAppp v3, created by Android enthusiasts joining the Droidcon 2021 in Berlin, coming to the GDG Booth and writing code, 15 minutes at a time

ZeThree App build at the GDG Community booth at Droidcon Berlin 2021. Come join the fun™. ZeWhat? Based on the previous success of the ZeAppp-app, thi

GDG Berlin Android 8 Sep 16, 2022
Ecormmerce app built using Android latest UI framework - Compose UI and data coming from Fake Store API

BuyCart ?? Android shopping app built with Jetpack Compose consuming FAKE STORE API I am trying to learn and follow some standard Android architecture

Henry Udorji 4 Aug 5, 2022