Share
Embed
Transcript
51 slides
-
VectorDrawable • Drawable described by SVG (Scalable Vector Graphics) format.
• API Level 21~ : OS supports • ~API Level 21 : Compatible by Support Library 23.2~ -
SVG (Scalable Vector Graphics) • Described the image by vector
path data https://www.w3.org/TR/SVG/ • Familiar with the web app. • Supported by many design tools. (Illustrator, Sketch etc,,,) -
1. Scalable with the high quality We can change the
image size without the degradation of image quality. 3BTUFSJNBHF 7FDUPSJNBHF -
2. Reduce apk size Since we don’t have to put
many image files for each dpi, we can reduce apk size. -
3. Animatable As MaterialDesign recommends, we can add the animation
to the images. Such as rotation, move, transform. https://material.io/guidelines/motion/creative-customization.html#creative-customization- icons -
Caution • From a performance point of view, Google recommends
that we limit a vector image to a maximum 200 x 200 dp. https://developer.android.com/studio/write/vector-asset-studio.html • VectorDrawables use a Bitmap cache, but the first rendering speed is not so fast. We shouldn't use too complex vector image. https://upday.github.io/blog/vector_drawables_optimisation/ -
build.gradle • Actually, we don’t have to add “support-vector- drawable”
to dependencies. Because appcompat contains it. • But I think it’s good to add it because appcompat might change current dependencies. -
Activity • After Support Library 23.3~, you have to write
this to enable VectorDrawableCompat in each Activities. -
ImageView, ImageButton • Use “app:srcCompat” instead of “android:src”
• Use “setImageResource()” to set an image programatically -
TextView, Button • Create“StateListDrawable” and use it to set “drawableLeft”
or “drawableRight”. • Do you want to know why does this work? Please see this! http://qiita.com/takahirom/items/c6f5a3204210d1e95c70 ic_play_48dp_state.xml -
ImageView ImageButton Use “app:srcCompat” attribute. Toolbar menu icon Bottom navigation
icon Navigation drawer icon Use VectorDrawable directly. TextView Button Create StateListDrawable and use it instead of VectorDrawable. • VectorDrawableରԠ·ͱΊ (Japanese) http://qiita.com/konifar/items/bf581b8f23dea7b30f85 -
VectorAsset • File > New > VectorAsset • You can
put VectorDrawable easily. -
vector-drawable-previewer • It’s difficult to review VectorDrawable on the browser.
This chrome extension shows VectorDrawable graphically. https://github.com/jmatsu/vector-drawable-previewer -
What is AnimatedVectorDrawable? We can animate VectorDrawable by using ObjectAnimator
and AnimatorSet. 1. Change colors, position. 2. Rotate icon. 3. Morph to other icon shape. -
Introduction 1. Put arrow and stop vector drawable xml. 2.
Create animator xml. 3. Create AnimatedVectorDrawable xml. res/drawable/ic_play.xml res/drawable/ic_pause.xml -
Introduction 1. Put arrow and stop vector drawable xml. 2.
Create animator xml. 3. Create AnimatedVectorDrawable xml. animator/anim_play_to_pause.xml animator/anim_pause_to_play.xml -
Introduction 1. Put arrow and stop vector drawable xml. 2.
Create animator xml. 3. Create AnimatedVectorDrawable xml. drawable/avd_play_to_pause.xml drawable/avd_pause_to_play.xml -
1. How to start animation? • AnimatedVectorDrawable is not like
a StateListDrawable. • Actually we need to call start() method programmatically :( -
2. Caution for morphing • Actually we can not animate
no matter what kind of VectorDrawable. • Official document says that “Note that the paths must be compatible for morphing. In more details, the paths should have exact same length of commands, and exact same length of parameters for each commands.” https://developer.android.com/reference/android/graphics/drawable/ AnimatedVectorDrawable.html -
Can I morph or not? • M38,24 L16,10 L16,38z M12
10 L20 10 L20 38 L12 38z M28 10 L36 10 L36 38 L28 38z • M38,24 L38,24 L16,24 L16,10z M38,24 L38,24 L16,38 L16,24z M12,10 L20,10 L20,38 L12,38z M28,10 L36,10 L36,38 L28,38z -
Can I morph or not? • M38,24 L16,10 L16,38z M12
10 L20 10 L20 38 L12 38z M28 10 L36 10 L36 38 L28 38z • M38,24 L38,24 L16,24 L16,10z M38,24 L38,24 L16,38 L16,24z M12,10 L20,10 L20,38 L12,38z M28,10 L36,10 L36,38 L28,38z ̋ ✕ -
Same shape M38,24 L38,24 L16,24 L16,10 z
M38,24 L38,24 L16,38 L16,24 z -
M38,24 L38,24 L16,24 L16,10 z M38,24
L38,24 L16,38 L16,24 z M12,10 L20,10 L20,38 L12,38 z M28,10 L36,10 L36,38 L28,38 z Official document says that “Note that the paths must be compatible for morphing. In more details, the paths should have exact same length of commands, and exact same length of parameters for each commands.” -
M38,24 L38,24 L16,24 L16,10 z M38,24
L38,24 L16,38 L16,24 z M12,10 L20,10 L20,38 L12,38 z M28,10 L36,10 L36,38 L28,38 z 10 commands length and exactly same commands (Alphabet) -
It’s so hard :( • You can use VectAlign. This
tool create vector path that allows morphing each vector paths. https://github.com/bonnyfone/vectalign -
AndroidIconAnimator • You can simulate VectorDrawable Animation and download it
from web! https://romannurik.github.io/AndroidIconAnimator/ -
Note • Plaid uses AnimatedVectorDrawable effectively. We can learn a
lot from it. https://github.com/nickbutcher/plaid • VectAlign is awesome tool to create vector path that allows morphing each vector paths. https://github.com/bonnyfone/vectalign • Documentation and introduction video. https://developer.android.com/reference/android/graphics/drawable/ AnimatedVectorDrawable.html https://www.youtube.com/watch?v=wlFVIIstKmA