Vector graphics in Android

后端 未结 6 1896
遇见更好的自我
遇见更好的自我 2021-01-30 21:56

I\'m working on an application that displays someone else\'s database of images. The images they have are all vector graphics and can be converted to any format, however keepin

6条回答
  •  梦谈多话
    2021-01-30 22:07

    This question is old. But hope my answer helps future visitors here.

    We place VectorDrawable files in drawable folder. AnimatedVectorDrawable also is a drawable . Hence, We place these files also in drawable folder. Below are examples of the two :

    vd_omega.xml

        
    
                
    
    
    
            
    

    avd_omega_animator.xml

    
    
               
    
    
    
    
    

    Then you can animate using an animator file like following:

    trimpath_animator.xml

    
    
    
    
    

    You can have more animators in same file for various properties.

    In your layout file

    activity_main.xml

    
    
        
    
    
    

    In your activity write the following code in the onCreate:

    import ... import ...

    public class MyActivity extends Activity{
    
    ImageView myImage;
    
    
    ...
    ...
    setContentView(R.layout.activity_main);
    myImage = (ImageView)findViewById(R.id.my_image);
    Drawable d = myImage.getDrawable():
    if(d instance of Animatable){
    d.start;
    }
    

    and see the fun.

    Just as I used getDrawable above you can also use other methods to place drawables in the ImageView like setImageDrawable("d") etc.

    You can also refer to "Introduction to Icon animation techniques" of Mr. Alex Lockwood at:

    https://www.androiddesignpatterns.com/2016/11/introduction-to-icon-animation-techniques.html

    for good examples.

    Hope I gave you helpful answer.

    All the example code which I gave above works. It is also simple and straight.

提交回复
热议问题