android 文字动画显示,用粒子动画显示各种文字的 Android 自定义 View

一、总述

ParticleTextView 是一个 Android 平台的自定义 view 组件,可以用彩色粒子组成指定的文字,并配合多种动画效果和配置属性,呈现出丰富的视觉效果。

186342288b68882b9fc2996c880981bb.gif

二、使用

1. 引入依赖 compile 'yasic.library.ParticleTextView:particletextview:0.0.3'复制代码

2. 加入到布局文件中

android:id="@+id/particleTextView"

android:layout_width="match_parent"

android:layout_height="match_parent" />复制代码

3. 实例化配置信息类 ParticleTextViewConfig ParticleTextView particleTextView = (ParticleTextView) findViewById(R.id.particleTextView);

RandomMovingStrategy randomMovingStrategy = new RandomMovingStrategy();

ParticleTextViewConfig config = new ParticleTextViewConfig.Builder()

.setRowStep(8)

.setColumnStep(8)

.setTargetText("Random")

.setReleasing(0.2)

.setParticleRadius(4)

.setMiniDistance(0.1)

.setTextSize(150)

.setMovingStrategy(randomMovingStrategy)

.instance();

particleTextView.setConfig(config);复制代码

4. 启动动画 particleTextView.startAnimation();复制代码

5. 暂停动画 particleTextView1.stopAnimation();复制代码

三、API说明

粒子移动轨迹策略 MovingStrategy

移动轨迹策略继承自抽象类 MovingStrategy,可以自己继承并实现其中的 setMovingPath 方法,以下是自带的几种移动轨迹策略。

RandomMovingStrategy

767d2e431452abe110bb19223310acfa.png

CornerStrategy

8651f509474cf67c283d3e36e9389858.gif

HorizontalStrategy

280b180980f29f48c7f5539dc31b542c.gif

BidiHorizontalStrategy

f9be9f90958c93770c6845b179591fdf.gif

VerticalStrategy

2f23bb67dbe9c1f17fcf77ddef025261.gif

BidiVerticalStrategy

eacea613b4d239c42aa6d08612e9f0e4.gif

配置信息类 ParticleTextViewConfig

配置信息类采用工厂模式创建,以下属性均为可选属性。

设置显示的文字 setTargetText(String targetText)复制代码

设置文字大小 setTextSize(int textSize)复制代码

设置粒子半径 setParticleRadius(float radius)复制代码

设置横向和纵向像素采样间隔

采样间隔越小生成的粒子数目越多,但绘制帧数也随之降低,建议结合文字大小与粒子半径进行调节。 setColumnStep(int columnStep)

setRowStep(int rowStep)复制代码

设置粒子运动速度 setReleasing(double releasing)复制代码

指定时刻,粒子的运动速度由下列公式决定,其中 Vx 和 Vy 分别是 X 与 Y 方向上的运动速度,target 与 source 分别是粒子的目的坐标与当前坐标 Vx = (targetX - sourceX) * releasing

Vy = (targetY - sourceY) * releasing复制代码

设置最小判决距离

当粒子与目的坐标距离小于最小判决距离时将直接移动到目的坐标,从而减少不明显的动画过程。 setMiniDistance(double miniDistance)复制代码

设置粒子颜色域

默认使用完全随机的颜色域 setParticleColorArray(String[] particleColorArray)复制代码

设置粒子移动轨迹策略

默认使用随机分布式策略 setMovingStrategy(MovingStrategy movingStrategy)复制代码

设置不同路径间动画的间隔时间

delay < 0 时动画不循环 setDelay(Long delay)复制代码

ParticleTextView类

指定配置信息类 setConfig(ParticleTextViewConfig config)复制代码

开启动画 void startAnimation()复制代码

停止动画 void stopAnimation()复制代码

获取动画是否暂停

暂停是指动画完成了一段路径后的暂留状态 boolean isAnimationPause()复制代码

获取动画是否停止

停止是指动画完成了一次完整路径后的停止状态 boolean isAnimationStop()复制代码

License Copyright 2017 Yasic

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.复制代码

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值