Java Android中的笔刷绘制动画效果
我想创建下面的画笔效果。我不知道怎么做,也不知道从哪里开始。在网络上搜索解决方案没有产生任何有用的结果。任何帮助都将不胜感激Java Android中的笔刷绘制动画效果,java,android,android-animation,Java,Android,Android Animation,我想创建下面的画笔效果。我不知道怎么做,也不知道从哪里开始。在网络上搜索解决方案没有产生任何有用的结果。任何帮助都将不胜感激 有很多方法可以做到这一点。最好的方法可能是在第三方工具中渲染动画,然后在设备上播放,但也有一些更简单的方法-例如,只使用ValueAnimator和一些绘图工具或AnimationDrawable-来创建类似的内容 我将在这个答案中演示ValueAnimator版本。结果应该如下所示: <?xml version="1.0" encoding="utf-8"?>
有很多方法可以做到这一点。最好的方法可能是在第三方工具中渲染动画,然后在设备上播放,但也有一些更简单的方法-例如,只使用
ValueAnimator
和一些绘图工具或AnimationDrawable
-来创建类似的内容
我将在这个答案中演示ValueAnimator
版本。结果应该如下所示:
<?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>
此动画包含两个部分:
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>
在本例中,值animator
设置为无限重复。在AnimatorUpdateListener
中,我更新translationX属性以在屏幕上同时移动绘画和笔刷。绘画被屏幕的宽度偏移,因此它从屏幕开始,一直移动到画笔后面,以在屏幕上创建画笔绘画的错觉
如果您还有任何问题,请随时提问 由于您的动画是动画GIF,我建议您看看以下答案: