最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中使用Vectors(2)繪制優(yōu)美的路徑動(dòng)畫

 更新時(shí)間:2016年03月08日 10:58:20   作者:SpikeKing  
這篇文章主要介紹了Android中使用Vectors(2)繪制優(yōu)美的路徑動(dòng)畫的相關(guān)資料,需要的朋友可以參考下

 隨著互聯(lián)網(wǎng)技術(shù)的不斷進(jìn)步,Android的Vector圖像的時(shí)代已經(jīng)到來. 在Google的最新支持庫v23.2中, AppCompat類已經(jīng)使用Vector圖像, 使得AAR包減少9%, 大約70KB, 惠及所有高版本的應(yīng)用. 當(dāng)然我們也可以使用Vector, 瘦身應(yīng)用. Vector圖像是SVG格式在Android的表現(xiàn)形式. SVG圖像適應(yīng)屏幕, 圖片較小, 還有很多優(yōu)點(diǎn), 參考.

關(guān)于Vectors的分析, 主要分為兩節(jié):

(1) 使用SVG圖像瘦身應(yīng)用, 參考.

(2) 繪制優(yōu)美的路徑動(dòng)畫, 參考.

本文是第二節(jié), 關(guān)于Vector動(dòng)畫.

Android

SDK Manager提示支持庫更新

Support

使用Vector動(dòng)畫主要有三個(gè)部分: Vector圖像, 路徑動(dòng)畫, Animated-Vector圖像.

本文源碼的Github下載地址.

動(dòng)畫

Animation

1. Vector圖像

SVG格式的圖片, 轉(zhuǎn)換為Vector圖像資源, 可以使用AS2.0的轉(zhuǎn)換工具, 也可以是在線轉(zhuǎn)換工具, 參考. 圖像需要路徑(path)樣式, 便于繪制, 如

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="256dp"
android:height="256dp"
android:viewportHeight="70"
android:viewportWidth="70">
<path
android:name="heart1"
android:pathData="..."
android:strokeColor="#E91E63"
android:strokeWidth="1"/>
<path
android:name="heart2"
android:pathData="..."
android:strokeColor="#E91E63"
android:strokeWidth="1"/>
</vector>

2. 路徑動(dòng)畫

使用屬性動(dòng)畫, 控制繪制狀態(tài).

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="6000"
android:propertyName="trimPathEnd"
android:valueFrom="0"
android:valueTo="1"
android:valueType="floatType"/>

ObjectAnimator的trimPathEnd屬性決定繪制path的數(shù)量, 其余部分不會(huì)繪制, 其取值區(qū)間是0到1. duration屬性表示持續(xù)時(shí)間, 6000即6秒.

3. Animated-Vector圖像

把Vector圖像的路徑(path), 應(yīng)用于路徑動(dòng)畫(objectAnimator), 控制繪制.

<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/v_heard">
<target
android:name="heart1"
android:animation="@animator/heart_animator"/>
<target
android:name="heart2"
android:animation="@animator/heart_animator"/>
...
</animated-vector>

4. 顯示動(dòng)畫

需要Android 5.0(21)以上版本, 才能使用Vector動(dòng)畫, 即AnimatedVectorDrawable類.

// 只支持5.0以上.
private void animateImage() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// 獲取動(dòng)畫效果
AnimatedVectorDrawable mAnimatedVectorDrawable = (AnimatedVectorDrawable)
ContextCompat.getDrawable(getApplication(), R.drawable.v_heard_animation);
mIvImageView.setImageDrawable(mAnimatedVectorDrawable);
if (mAnimatedVectorDrawable != null) {
mAnimatedVectorDrawable.start();
}
}
}

AnimatedVectorDrawable的start方法就是動(dòng)畫啟動(dòng)功能.

使用Vector動(dòng)畫比gif動(dòng)畫節(jié)省應(yīng)用資源, 可以給用戶更好的體驗(yàn). 推薦一個(gè)有趣的SVG庫.

以上所述是小編給大家介紹的Android中使用Vectors(2)繪制優(yōu)美的路徑動(dòng)畫,希望對(duì)大家有所幫助!

相關(guān)文章

  • Android startService的使用與Service生命周期案例詳解

    Android startService的使用與Service生命周期案例詳解

    這篇文章主要介紹了Android startService的使用與Service生命周期案例詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • android使用surfaceview+MediaPlayer播放視頻

    android使用surfaceview+MediaPlayer播放視頻

    這篇文章主要為大家詳細(xì)介紹了android使用surfaceview+MediaPlayer播放視頻,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • 優(yōu)化Gradle提升Gradle編譯速度

    優(yōu)化Gradle提升Gradle編譯速度

    今天小編就為大家分享一篇關(guān)于優(yōu)化Gradle提升Gradle編譯速度的文章,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • Android實(shí)現(xiàn)Bitmap位圖旋轉(zhuǎn)效果

    Android實(shí)現(xiàn)Bitmap位圖旋轉(zhuǎn)效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)Bitmap位圖旋轉(zhuǎn)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Android編程之Animation動(dòng)畫詳解

    Android編程之Animation動(dòng)畫詳解

    這篇文章主要介紹了Android編程之Animation動(dòng)畫具體用法,結(jié)合實(shí)例非常詳細(xì)的總結(jié)分析了Android中Animation動(dòng)畫所涉及的相關(guān)知識(shí)點(diǎn)與動(dòng)畫具體實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-01-01
  • Android TextView添加超鏈接的方法示例

    Android TextView添加超鏈接的方法示例

    這篇文章主要介紹了Android TextView添加超鏈接的方法,結(jié)合實(shí)例形式分析了TextView控件添加HTML超鏈接的實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-10-10
  • 將Eclipse工程轉(zhuǎn)Android Studio工程的步驟與注意事項(xiàng)

    將Eclipse工程轉(zhuǎn)Android Studio工程的步驟與注意事項(xiàng)

    這篇文章主要給大家介紹了將Eclipse工程轉(zhuǎn)Android Studio工程的方法步驟,并給大家分享了其中的一些注意事項(xiàng),文中將實(shí)現(xiàn)的步驟一步步介紹的非常詳細(xì),需要的朋友們可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • Android之EditText控制禁止輸入空格和回車

    Android之EditText控制禁止輸入空格和回車

    本文主要介紹了Android中使用EditText控制禁止輸入空格和回車的實(shí)現(xiàn)代碼。具有很好的參考價(jià)值。下面跟著小編一起來看下吧
    2017-04-04
  • Android build.gradle版本名打包配置的方法

    Android build.gradle版本名打包配置的方法

    這篇文章主要介紹了Android build.gradle版本名打包配置的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-02-02
  • 詳解Android中的多線程斷點(diǎn)下載

    詳解Android中的多線程斷點(diǎn)下載

    本文主要介紹了Android中多線程下載的幾個(gè)步驟以及實(shí)現(xiàn)功能的具體代碼,具有很好的參考價(jià)值,需要的朋友一起來看下吧
    2016-12-12

最新評(píng)論

南乐县| 丰镇市| 达日县| 东源县| 安龙县| 吴江市| 电白县| 吐鲁番市| 噶尔县| 安图县| 广州市| 南木林县| 金溪县| 万源市| 贡觉县| 巴塘县| 榆林市| 康定县| 宾川县| 年辖:市辖区| 西昌市| 萍乡市| 万载县| 惠安县| 德庆县| 外汇| 红桥区| 临颍县| 吐鲁番市| 凤凰县| 偏关县| 抚顺县| 大石桥市| 甘谷县| 桦川县| 昌江| 徐水县| 台中县| 南京市| 铜川市| 乌拉特后旗|