Vector Drawable、Animated Vector Drawable

制作VectorDrawable(文件目录:res/drawable)

选择Vector Asset

编辑图案

和普通图片一样使用

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#ffff0000"
        android:pathData="M8,5v14l11,-7z"/>
</vector>

Animated Vector Drawable

4个步骤

1.定义矢量资源,在res/drawable

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:name="play"
        android:fillColor="#FF000000"
        android:pathData="M15.41,16.09l-4.58,-4.59 4.58,-4.59L14,5.5l-6,6 6,6z"/>
</vector>

2.定义动画文件,在res/animtor

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator android:duration="200"
                    android:propertyName="pathData"
                    android:valueFrom="M15.41,16.09l-4.58,-4.59 4.58,-4.59L14,5.5l-6,6 6,6z"
                    android:valueTo="M8.59,16.34l4.58,-4.59 -4.58,-4.59L10,5.75l6,6 -6,6z"
                    android:valueType="pathType" />
</set>

3.绑定矢量资源和动画的关系,在res/animtor

<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
                 android:drawable="@drawable/ic_keyboard_arrow_left_black_24dp">
    <target
        android:animation="@animator/anim_play_stop"
        android:name="play"/>
</animated-vector>

4.开始动画

<ImageButton
        android:id="@+id/imgBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/animated_vector_menu_back"/>
ImageButton imageButton = (ImageButton) findViewById(R.id.imgBtn);
imageButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Drawable drawable = mImageButton.getDrawable();
        if (drawable instanceof Animatable){
            ((Animatable)drawable).start();
        }
    }
});
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值