2
A
回答
3
有很多方法可以做到这一点。最好的方法可能是在第三方工具中渲染动画,然后在设备上播放动画,但也有一些更简单的方法 - 例如使用ValueAnimator
和一些可绘制的或AnimationDrawable
来创建像这样的东西。
我要在此答案中演示ValueAnimator
版本。结果应该是这个样子:
有两个部分,以这个动画:
- 刷
- 油漆刷留下
对于刷我使用画笔的透明png图像。画笔留下的油漆只是一个带有黑色背景色的FrameLayout
。
使用FrameLayout
作为容器我将它们放在我的布局是这样的:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<FrameLayout
android:id="@+id/paint"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:background="@android:color/black"/>
<ImageView
android:id="@+id/brush"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/paint_brush"/>
</FrameLayout>
</FrameLayout>
执行动画中的代码非常简单:
final View brush = findViewById(R.id.brush);
final View paint = findViewById(R.id.paint);
final ValueAnimator animator = ValueAnimator.ofFloat(0.0f, 1.0f);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setDuration(6000L);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
final float progress = (float) valueAnimator.getAnimatedValue();
paint.setTranslationX(-paint.getWidth() * (1.0f - progress));
brush.setTranslationX(paint.getWidth() * progress);
}
});
animator.start();
的ValueAnimator
设置为无限重复这个例子。在AnimatorUpdateListener
中,我更新了translationX属性以将画笔和笔刷在屏幕上一起移动。油漆被屏幕宽度所抵消,因此它始终从屏幕开始移动并移动到笔刷后面,以在屏幕上创建画笔绘画的错觉。
如果您有任何其他问题随时问!
相关问题
- 1. Android动画效果
- 2. Android。动画效果
- 3. Android滑动效果动画
- 4. 圆形笔画的笔画动画以完整笔画结尾
- 5. 在inkpresenter中动画笔画
- 6. 画布专业绘画效果
- 7. 动画效果
- 8. 对android中的imageView动画效果
- 9. 动画刷几何绘图
- 10. 画布绘制效果
- 11. 在android中重置动画效果
- 12. uiimage动画效果
- 13. d3画布笔刷/选择
- 14. 如何制作Photoshop笔画效果?
- 15. UIComponent四周绘制笔画
- 16. 为angular2动画效果应用动画效果
- 17. 动画效果的onDraw()段
- 18. 动画效果recyclerview滚动
- 19. 刷卡刷新布局动画的android
- 20. 在Android中绘画
- 21. 关于android画布效果的效率
- 22. Android画廊动画视图无效
- 23. 改变笔画动画的方向
- 24. Android中的笔画问题Android
- 25. Page turn动画效果
- 26. 动画闪烁效果C#
- 27. jQuery效果,动画和CSS
- 28. MaxImage:没有动画效果
- 29. jQuery动画效果优化
- 30. jQuery动画效果问题
由于您的动画是一个动画GIF,我建议看看这个答案:http://stackoverflow.com/questions/3660209/display-animated-gif – Peter