SnowingView
来源:互联网 发布:mac怎么卸载迅雷 编辑:程序博客网 时间:2024/06/03 20:53
SnowingView
项目地址:SnowingView
简介:winter is coming...
winter is coming...
介绍
一个看起来还不错的下雪动画。
功能&&实现
- 使用 Matrix 产生随机大小、透明度的雪花
- 使用 HandlerThread 来计算雪花的下一个位置
- 使用加速度传感器判断用户在 X 轴的倾斜方向,使雪花产生左右飘动的效果
缺点&改进
- 还未用 LeakCanary 检测是否有内存泄漏的情况
- 暂时还不支持 wrap_content
- 可能会采用 SurfaceView 来绘制提高效率
实际效果
使用(如果有人想用的话)
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(); // 停止下雪 } } }); }}
参考
- 之前在开发者看到的 Android 下雪动画,但是,我并没有看懂作者的雪花下落算法
0 0
- SnowingView
- SnowingView
- 一个模拟下雪效果SnowingView
- VBoxDispDrvEnablePDEV
- [数据结构]--深入浅出红黑二叉树
- css flexbox 学习笔记(一)
- ios打包报错/Applications/Xcode.app/...../XcodeDefault.xctoolchain/usr/bin/strip failed with exit code 1
- DrvEnableDriver
- SnowingView
- VBoxDispDrvDisableDirectDraw
- PAT 1023. Have Fun with Numbers
- 打开摄像头
- VBoxDispDrvEnableDirectDraw
- java 代码规范
- 如何判断桌面云的显示图像错误是否是虚拟化平台导致的
- SQL子查询
- Dokuwiki配置修改上传文件类型以及大小