android今日头条刷新,仿今日头条刷新vector动画
一般的刷新動畫是一個圈圈在轉,而頭條的比較特殊,直接上寫好的效果圖(一直不知道怎么把圖片尺寸調(diào)小o(╯□╰)o)吧~
刷新動畫_.gif
首先整個效果是通過SVG和vector來實現(xiàn)的,如果不是很了解,請看大佬的文章:
SVG學習--AnimatedVectorDrawable的使用
動畫思路:
整個view可以分為五個部分:
1、最外面的殼(不需要動畫)
2、中間矩形框
3、矩形框中的灰色矩形塊
4、三根短線
5、三根長線
第一步:在drawable文件夾下新建名為refresh的vector文件:
android:width="200dp"
android:height="200dp"
android:viewportHeight="200"
android:viewportWidth="200">
android:name="out_rect"
android:pathData="M70,60
L130,60
Q140,60 140,70
L140,130
Q140,140 130,140
L70,140
Q60,140 60,130
L60,70
Q60,60 70,60"
android:strokeColor="@color/colorCustomHeaderLine"
android:strokeWidth="2" />
android:name="middle_rect"
android:pathData="M71,75
L100,75
L100,95
L72,95
L72,75"
android:strokeColor="@color/colorCustomHeaderLine"
android:strokeWidth="2" />
android:name="inner_rect"
android:fillColor="@color/colorCustomHeaderInner"
android:pathData="M73,76
L99,76
L99,94
L73,94" />
android:name="short_lines"
android:pathData="M108,75
L128,75
M108,85
L128,85
M108,95
L128,95"
android:strokeColor="@color/colorCustomHeaderLine"
android:strokeWidth="2" />
android:name="long_lines"
android:pathData="
M72,105
L128,105
M72,115
L128,115
M72,125
L128,125"
android:strokeColor="@color/colorCustomHeaderLine"
android:strokeWidth="2" />
打開xml右邊的預覽,我們可以看到效果
效果圖.png
第二步:在drawable文件夾下新建名為refresh_vector的animated-vector
android:drawable="@drawable/refresh">
android:name="middle_rect"
android:animation="@animator/anim_middle_rect" />
android:name="short_lines"
android:animation="@animator/anim_short_lines" />
android:name="long_lines"
android:animation="@animator/anim_long_lines" />
android:name="inner_rect"
android:animation="@animator/anim_inner_rect" />
這里需要注意幾點:
1、android:drawable="@drawable/refresh"這里一定要引用上面的refresh文件
2、target標簽下的name一定要和refresh中的path標簽下的名字一致
第三步:新建animator文件夾(不是anim),并在下面新建短線、長線、中間矩形框和里面矩形對應的objectAnimator集合:
anim_middle_rect.xml:
android:ordering="sequentially">
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M71,75
L100,75
L100,95
L72,95
L72,75"
android:valueTo="M99,75
L128,75
L128,95
L100,95
L100,75"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M99,75
L128,75
L128,95
L100,95
L100,75"
android:valueTo="M99,105
L128,105
L128,125
L100,125
L100,105"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M99,105
L128,105
L128,125
L100,125
L100,105"
android:valueTo="M71,105
L100,105
L100,125
L72,125
L72,105"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M71,105
L100,105
L100,125
L72,125
L72,105"
android:valueTo="M71,75
L100,75
L100,95
L72,95
L72,75"
android:valueType="pathType" />
anim_short_lines.xml:
android:ordering="sequentially">
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M108,75
L128,75
M108,85
L128,85
M108,95
L128,95"
android:valueTo="M72,105
L128,105
M72,115
L128,115
M72,125
L128,125"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M72,105
L128,105
M72,115
L128,115
M72,125
L128,125"
android:valueTo="M72,105
L92,105
M72,115
L92,115
M72,125
L92,125"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M72,105
L92,105
M72,115
L92,115
M72,125
L92,125"
android:valueTo="M72,75
L128,75
M72,85
L128,85
M72,95
L128,95"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M72,75
L128,75
M72,85
L128,85
M72,95
L128,95"
android:valueTo="M108,75
L128,75
M108,85
L128,85
M108,95
L128,95"
android:valueType="pathType" />
anim_long_lines.xml:
android:ordering="sequentially">
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M72,105
L128,105
M72,115
L128,115
M72,125
L128,125"
android:valueTo="M72,75
L92,75
M72,85
L92,85
M72,95
L92,95"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M72,75
L92,75
M72,85
L92,85
M72,95
L92,95"
android:valueTo="M72,75
L128,75
M72,85
L128,85
M72,95
L128,95"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M72,75
L128,75
M72,85
L128,85
M72,95
L128,95"
android:valueTo="M108,105
L128,105
M108,115
L128,115
M108,125
L128,125"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M108,105
L128,105
M108,115
L128,115
M108,125
L128,125"
android:valueTo="M72,105
L128,105
M72,115
L128,115
M72,125
L128,125"
android:valueType="pathType" />
anim_inner_rect.xml
android:ordering="sequentially">
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M73,76
L99,76
L99,94
L73,94"
android:valueTo="M101,76
L127,76
L127,94
L101,94"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M101,76
L127,76
L127,94
L101,94"
android:valueTo="M101,106
L127,106
L127,124
L101,124"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M101,106
L127,106
L127,124
L101,124"
android:valueTo="M73,106
L99,106
L99,124
L73,124"
android:valueType="pathType" />
android:duration="500"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="pathData"
android:valueFrom="M73,106
L99,106
L99,124
L73,124"
android:valueTo="M73,76
L99,76
L99,94
L73,94"
android:valueType="pathType" />
最后一步,在activity中:
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
final AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) ContextCompat.getDrawable(this, R.drawable.refresh_vector);
findViewById(R.id.imageView).setImageDrawable(animatedVectorDrawable);
animatedVectorDrawable.start();
//循環(huán)動畫貌似只能這樣。。。
final Handler mainHandler = new Handler(Looper.getMainLooper());
animatedVectorDrawable.registerAnimationCallback(new Animatable2.AnimationCallback() {
@Override
public void onAnimationEnd(Drawable drawable) {
mainHandler.post(new Runnable() {
@Override
public void run() {
animatedVectorDrawable.start();
}
});
}
});
總結
以上是生活随笔為你收集整理的android今日头条刷新,仿今日头条刷新vector动画的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos 使用java_如何在Cen
- 下一篇: 当前不会命中断点_原神:体验服新角色胡桃