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畫布/ Paint - 更改Android畫布筆刷的刷子尺寸
- 4. 繪製畫筆
- 5. Android滑動效果動畫
- 6. 圓形筆畫的筆畫動畫以完整筆畫結尾
- 7. Android單擊動畫效果
- 8. Android觸摸動畫效果
- 9. 在Android中將畫外屏繪製爲畫布效果
- 10. 在inkpresenter中動畫筆畫
- 11. 畫布專業繪畫效果
- 12. 動畫效果
- 13. 對android中的imageView動畫效果
- 14. jQuery的動畫動畫效果後生效,之後動畫效果
- 15. 動畫刷幾何繪圖
- 16. 動畫效果的UITableViewCell的塊動畫
- 17. 畫布繪製效果
- 18. 在android中重置動畫效果
- 19. 在android中設置動畫效果?
- 20. drawImage下的繪圖筆畫
- 21. Jquery使用動畫效果動畫效果的Flash動畫文本
- 22. 動畫效果ngRepeat
- 23. iOS動畫效果
- 24. uiimage動畫效果
- 25. 動畫jQuery效果
- 26. d3畫布筆刷/選擇
- 27. 如何製作Photoshop筆畫效果?
- 28. UIComponent四周繪製筆畫
- 29. 手指畫筆中的筆畫刪除
- 30. 爲angular2動畫效果應用動畫效果
由於您的動畫是一個動畫GIF,我建議看看這個答案:http://stackoverflow.com/questions/3660209/display-animated-gif – Peter