美文网首页
SVG在Android中的使用

SVG在Android中的使用

作者: lixinxin | 来源:发表于2018-08-31 15:36 被阅读7次

    svg

    M=moveto(M X,Y): 将画笔移动到指定的坐标位置

    L=lineto(L X,Y): 画直线到指定的坐标位置

    H=horizontal lineto(H X): 画水平线到指定的X坐标位置

    V=vertical lineto(V Y): 画垂直线到指定的Y坐标位置

    A=elliptical Arc(A RX,RY,XROTATION,FLAG1,FLAG2,X,Y): 弧线

    使用

    <vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="100dp"
    android:height="100dp"
    android:tint="#02A426"
    android:viewportHeight="100"
    android:viewportWidth="100">
    <path
        android:name="lee"
        android:pathData="M0,0,V100,H40,V50,H60,V100,H100V0,z"
        android:strokeColor="#FF0000"
        android:strokeWidth="5" />
    </vector>
    

    动画

    <animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:drawable="@drawable/ic_title_black_24dp">
    
        <target
            android:name="lee"
            android:animation="@animator/anim_bar_fill" />
    </animated-vector>
    
    anim_bar_fill.xml
    
    <objectAnimator
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:propertyName="trimPathEnd"
        android:repeatCount="0"
        android:valueFrom="0"
        android:valueTo="1"
        android:valueType="floatType"/>
    
    //android 5.0以上可以使用
     if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                final AnimatedVectorDrawable anim1 = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable.anim);
                final ImageView logo = ((ImageView) findViewById(R.id.logo));
                logo.setImageDrawable(anim1);
                anim1.start();
            }
    
    

    相关文章

      网友评论

          本文标题:SVG在Android中的使用

          本文链接:https://www.haomeiwen.com/subject/kkjswftx.html