安卓系統(tǒng)APP開發(fā)怎樣實現(xiàn)Vector動態(tài)圖的使用?深圳APP開發(fā)公司本文詳細來解決這個問題,功能實現(xiàn)動畫功能是利用AnimatedVectorDrawable類實現(xiàn)的,需要創(chuàng)建3類XML文件:
1.在res/drawable文件夾中創(chuàng)建定義具有動畫屬性的VectorDrawable對象的XML文件,文件名為vector_drawable.xml,內(nèi)容如下所示:
< vector xmlns: android=" http:// schemas. android. com/ apk/ res/ android" android: height=" 64dp"
android: width=" 64dp" android: viewportHeight=" 600" android: viewportWidth=" 600" > < group android: name=" rotationGroup" android: pivotX=" 300. 0" android: pivotY=" 300. 0" android: rotation=" 90. 0" > < path android: name=" pathMorph" android: fillColor="# 000000" android: pathData=" M300, 70 l 0,- 70 70, 70 0, 0 -70, 70z" /> </ group> </ vector>
2.在res/animator文件夾中創(chuàng)建動畫XML文件,在此使用了兩種動畫效果,需要創(chuàng)建兩個動畫文件,rotation.xml的內(nèi)容如下所示:
path_morph.xml的內(nèi)容如下所示:
< objectAnimator xmlns: android=" http:// schemas. android. com/ apk/ res/ android" android: duration=" 6000" android: propertyName=" rotation" android: valueFrom=" 0" android: valueTo=" 360" />
3.在res/drawable文件夾中創(chuàng)建定義AnimatedVectorDrawable對象的XML文件,文件名為vector_animated.xml,內(nèi)容如下所示:
< set xmlns: android=" http:// schemas. android. com/ apk/ res/ android"> < objectAnimator android: duration=" 3000" android: propertyName=" pathData" android: valueFrom=" M300, 70 l 0,- 70 70, 70 0, 0 -70, 70z" android: valueTo=" M300, 70 l 0,- 70 70, 0 0, 140 -70, 0 z" android: valueType=" pathType"/> </ set>
android:drawable的值就是之前創(chuàng)建的定義VectorDrawable對象的XML文件對象。target中的android:name值就是之前創(chuàng)建的定義VectorDrawable對象的XML文件vector_drawable.xml中的group與path的android:name的值。android:animation的值就是之前創(chuàng)建的動畫XML文件對象。在Layout文件中添加一個圖像控件顯示動畫,具體代碼如下:
< animated- vector xmlns: android=" http:// schemas. android. com/ apk/ res/ android" android: drawable="@ drawable/ vector_ drawable" > < target android: name=" rotationGroup" android: animation="@ animator/ rotation" />
< target android: name=" pathMorph" android: animation="@ animator/ path_ morph" /> </ animated- vector>
< ImageView android: id="@+ id/ image_ anim_ view" android: layout_ width=" wrap_ content" android: layout_ height=" wrap_ content" app: srcCompat="@ drawable/ vector_ animated" android: layout_ below="@+ id/ textView"
android: layout_ alignRight="@+ id/ textView" android: layout_ alignEnd="@+ id/ textView" android: layout_ marginTop=" 24dp" />
具體播放動畫的功能代碼如下:
ImageView imageView = (ImageView) findViewById( R. id. image_ anim_ view); Drawable drawable = imageView. getDrawable(); ((AnimatedVectorDrawable) drawable). start();
好了,APP開發(fā)公司本文關(guān)于“安卓系統(tǒng)APP開發(fā)怎樣實現(xiàn)Vector動態(tài)圖的使用”的實操方法就介紹到這里,謝謝關(guān)注,博納網(wǎng)絡(luò)編輯整理。