{"id":1652,"date":"2024-04-09T10:25:27","date_gmt":"2024-04-09T02:25:27","guid":{"rendered":"https:\/\/www.gyxwsjdxh.com\/?p=1652"},"modified":"2024-04-09T10:25:27","modified_gmt":"2024-04-09T02:25:27","slug":"android%e8%bd%a6%e8%bd%bdhmi-lottie%e8%ae%b2%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.gyxwsjdxh.com\/1652.html","title":{"rendered":"Android\u8f66\u8f7dHMI\u2014Lottie\u8bb2\u89e3"},"content":{"rendered":"\n
\n
\u591a\u5e74\u4ee5\u524d\u6c7d\u8f66\u8fd8\u662f\u4ee5\u673a\u68b0\u4eea\u8868\u4e3b\u4f53\u7684\u5e74\u4ee3\uff0c\u5404\u5927\u6c7d\u8f66\u4e3b\u673a\u5382\u5546\u5e76\u4e0d\u5341\u5206\u5173\u6ce8\u64cd\u4f5c\u7cfb\u7edfUI\u7684\u4ea4\u4e92\u529f\u80fd\uff0c\u4f46\u662f\u968f\u7740\u8f66\u8f7dSOC\u7b97\u529b\u7684\u4e0d\u65ad\u63d0\u9ad8\u4ee5\u53ca\u4e3b\u673a\u5382\u5546\u5bf9\u6c7d\u8f66\u5ea7\u8231\u7ade\u4e89\u7684\u767d\u70ed\u5316\u3002\u5ea7\u8231\u7684HMI\u5728\u8bbe\u8ba1\u4e0a\u5728\u5f3a\u8c03\u529f\u80fd\u6027\u7684\u540c\u65f6\u4e5f\u5f00\u59cb\u5173\u6ce8UI\u7684\u827a\u672f\u6027\uff0cHMI\u7684\u8bbe\u8ba1\u5e08\u4eec\u671f\u671b\u827a\u672f\u4e0e\u529f\u80fd\u5e94\u8be5\u534f\u540c\u5de5\u4f5c\uff0c\u8ba9\u7528\u6237\u6c89\u6d78\u5728\u201c\u7b2c\u4e09\u7a7a\u95f4\u201d\u7684\u4f53\u9a8c\u4e2d\u3002<\/p>\n
\u6709\u4e86\u9700\u6c42\u7a0b\u5e8f\u5458\u5c31\u9700\u8981\u5173\u6ce8\u5982\u4f55\u5b9e\u65bd\u548c\u843d\u5730\uff0c\u7136\u800cAndroid\u5e94\u7528\u672c\u8eab\u867d\u7136\u6709\u7740\u5b8c\u6574\u7684\u52a8\u753b\u6846\u67b6\u652f\u6301\uff0c\u4f46\u662f\u5f00\u53d1\u590d\u6742\u3001\u8c03\u8bd5\u8017\u65f6\uff0c\u5927\u578b\u7684gif\u6216\u9010\u5e27\u52a8\u753b\u5bf9\u4e8eCPU&\u5185\u5b58\u5360\u7528\u90fd\u4e0d\u592a\u7406\u60f3\uff0c\u6240\u4ee5\u8bb8\u591aAndroid\u7684\u624b\u673a\u5e94\u7528\u57fa\u672c\u4e0a\u4e0d\u600e\u4e48\u6709\u52a8\u753b\u3002\u800c\u4e14\u8f66\u8f7dHMI\u4e0a\u8d8a\u6765\u8d8a\u591a\u7684\u5f00\u59cb\u5f15\u5165\u5404\u79cd\u5149\u5f71\u3001\u7c92\u5b50\u6548\u679c\uff0c\u5982\u679c\u57fa\u4e8eAndroid\u7684\u539f\u751f\u63a7\u4ef6\u6765\u5b9e\u73b0\u8fd9\u4e9b\u7c92\u5b50\u6548\u679c\uff0c\u96be\u5ea6\u975e\u5e38\u5927\uff0c\u8fd9\u5c31\u9700\u8981\u4eca\u5929\u7684\u4e3b\u89d2Lottie\u6765\u5b9e\u73b0\u4e86\u3002<\/p>\n
Lottie\u662f\u4e00\u79cd\u57fa\u4e8eJSON\u7684\u52a8\u753b\u6587\u4ef6\u683c\u5f0f\uff0c\u5b83\u4f7f\u8bbe\u8ba1\u5e08\u80fd\u591f\u5728\u4efb\u4f55\u5e73\u53f0\u4e0a\u53d1\u5e03\u52a8\u753b\uff0c\u5c31\u50cf\u53d1\u5e03\u9759\u6001\u8d44\u4ea7\u4e00\u6837\u7b80\u5355\u3002\u5b83\u4eec\u662f\u5728\u4efb\u4f55\u8bbe\u5907\u4e0a\u5de5\u4f5c\u7684\u5c0f\u6587\u4ef6\uff0c\u53ef\u4ee5\u5728\u4e0d\u8fdb\u884c\u50cf\u7d20\u5316\u7684\u60c5\u51b5\u4e0b\u653e\u5927\u6216\u7f29\u5c0f\u3002<\/p> GitHub\uff1ahttps:\/\/github.com\/airbnb\/lottie-android<\/a> \u5b98\u65b9\u6587\u6863\uff1ahttp:\/\/airbnb.io\/lottie\/<\/a>\n \u9002\u91cf\u56fe\u5f62\uff0c\u4e0d\u4f1a\u51fa\u73b0\u5931\u771f<\/p>\n \u5360\u7528\u7a7a\u95f4\u6bd4\u5e8f\u5217\u5e27\u52a8\u753b\u5c0f<\/p>\n \u53ef\u4ee5\u4fee\u6539\u5c5e\u6027\uff0c\u52a8\u6001\u751f\u6210\u53ef\u4ea4\u4e92\u7684\u52a8\u753b\uff08\u4f7f\u7528\u89c6\u9891\u52a8\u753b\u96be\u4ee5\u5b9e\u73b0\u4ea4\u4e92\u529f\u80fd\uff09<\/p>\n \u8282\u7701HMI\u7684\u5f00\u53d1\u3001\u8c03\u8bd5\u65f6\u95f4<\/p>\n \u53ef\u4ee5\u66f4\u8f7b\u677e\u7684\u5b9e\u73b0\u7c92\u5b50\u3001\u5149\u5f71\u7b49\u7279\u6548<\/p>\n \u7136\u540e\u5c31\u53ef\u4ee5\u5728\u5e03\u5c40\u6587\u4ef6\u4e2d\u4f7f\u7528LottieAnimationView\u4e86<\/p>\n \u7136\u540e\u8fd0\u884cAPP\u5c31\u53ef\u4ee5\u770b\u5230\u52a8\u753b\u6548\u679c<\/p>\n LottieAnimationView\u7ee7\u627f\u81eaAppCompatImageView\uff0c\u6240\u4ee5ImageView\u652f\u6301\u7684\u5c5e\u6027\uff0cLottieAnimationView\u90fd\u662f\u652f\u6301\u7684\uff0c\u8fd9\u90e8\u5206\u5c31\u4e0d\u518d\u4ecb\u7ecd\u4e86\u3002<\/p>lottie_fileName \u8bbe\u5b9alottie\u52a8\u753b\u6240\u5bf9\u5e94\u7684json\u6587\u4ef6\u5730\u5740\u3002json\u6587\u4ef6\u9ed8\u8ba4\u9700\u8981\u653e\u7f6e\u5728assets\u4e0b\uff0c\u8bbe\u5b9a\u65f6\u4e0d\u9700\u8981\u518d\u5f3a\u8c03assets \u5982\u679c\u8bbe\u5b9a app:lottie_fileName=”other\/HamburgerArrow.json”\uff0c\u90a3\u4e48lottie\u5c31\u4f1a\u8bfb\u53d6assets\/other\/HamburgerArrow.json\u3002 void setAnimationFromJson(String jsonString, @Nullable String cacheKey\uff09<\/p>lottie_rawRes \u8bbe\u5b9alottie\u52a8\u753b\u7684json\u6587\u4ef6\u5730\u5740\u3002json\u6587\u4ef6\u9664\u4e86\u53ef\u4ee5\u653e\u7f6eassets\u6587\u4ef6\u5939\u4e0b\uff0c\u8fd8\u53ef\u4ee5\u653e\u5728raw\u6587\u4ef6\u5939\u4e0b\u3002\u4f7f\u7528\u65f6\u9700\u8981\u6ce8\u610f\uff0c\u5229\u7528lottie_rawRes\u5f15\u5165\u8d44\u6e90\u65f6\uff0cjson\u6587\u4ef6\u540d\u524d\u9700\u8981\u52a0\u4e0a@raw\uff0c\u5e76\u4e14\u6587\u4ef6\u540d\u4e0d\u5e26.json\u540e\u7f00 imglottie_autoPlay \u8bbe\u5b9a\u662f\u5426\u81ea\u52a8\u64ad\u653e\uff0c\u53d6\u503c\u4e3atrue | false<\/p>\n lottie_loop \u8bbe\u5b9a\u662f\u5426\u5faa\u73af\u64ad\u653e\uff0c\u53d6\u503c\u4e3atrue | false<\/p>\n lottie_url \u5f53\u9700\u8981\u52a0\u8f7d\u5728\u7ebf\u8d44\u6e90\u65f6\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528lottie_url void setAnimationFromUrl(String url) void setAnimationFromUrl(String url, @Nullable String cacheKey)<\/p>\n lottie_fallbackRes \u8bbe\u7f6e\u4e00\u4e2adrawable\uff0c\u5982\u679clotticomposition\u7531\u4e8e\u4efb\u4f55\u539f\u56e0\u672a\u80fd\u52a0\u8f7d\uff0c\u5219\u5c06\u5448\u73b0\u8be5drawable\u3002 \u5982\u679c\u8fd9\u662f\u7f51\u7edc\u52a8\u753b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b83\u5411\u7528\u6237\u663e\u793a\u9519\u8bef\uff0c\u4e5f\u53ef\u4ee5\u6dfb\u52a0\u4e00\u4e2a\u5931\u8d25\u7684\u76d1\u542c\u5668\u91cd\u8bd5\u4e0b\u8f7d\u3002 void setFallbackResource(@DrawableRes int fallbackResource)<\/p>\n lottie_repeatMode \u8bbe\u5b9a\u5faa\u73af\u64ad\u653e\u7684\u987a\u5e8f\u3002\u53d6\u503c\u4e3arestart | reverse \u3002restart\u8868\u793a\u6b63\u5e38\u5faa\u73af\u64ad\u653e\uff0creverse\u8868\u793a\u5012\u5e8f\u64ad\u653e void setRepeatMode(@LottieDrawable.RepeatMode int mode) int getRepeatMode()<\/p>\n lottie_repeatCount \u8bbe\u5b9a\u5faa\u73af\u64ad\u653e\u6b21\u6570\uff0c\u53d6\u503c\u4e3a\u6574\u6570\u7c7b\u578b\u3002 void setRepeatCount(int count) int getRepeatCount()<\/p>\n lottie_imageAssetsFolder \u8bbe\u5b9a\u56fe\u7247\u6587\u4ef6\u5728assets\u6587\u4ef6\u5939\u4e0b\u7684\u8bbf\u95ee\u8def\u5f84\u3002\u6709\u7684\u65f6\u5019\u4f7f\u7528AE\u5bfc\u51falottie\u7684json\u65f6\u4e5f\u4f1a\u5bfc\u51fa\u4e00\u4e9b\u56fe\u7247\uff0c\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u8be5\u5c5e\u6027\u8bbe\u5b9a\u56fe\u7247\u7684\u5730\u5740\u3002 void setImageAssetsFolder(String imageAssetsFolder) String getImageAssetsFolder()<\/p>\n void setFrame(int frame) \u5c06\u8fdb\u5ea6\u8bbe\u7f6e\u4e3a\u6307\u5b9a\u7684\u5e27\u3002\u5c06\u8fdb\u5ea6\u8bbe\u7f6e\u4e3a\u6307\u5b9a\u7684\u5e27\u3002\u5982\u679c\u5c1a\u672a\u8bbe\u7f6e\u5408\u6210\uff0c\u5219\u8fdb\u5ea6\u5c06\u5728\u8bbe\u7f6e\u65f6\u8bbe\u7f6e\u4e3a\u5e27\u3002 \u901a\u8fc7int getFrame()\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u6e32\u67d3\u7684\u5e27\u3002<\/p>\n void setMaxFrame(int endFrame) \u8bbe\u7f6e\u64ad\u653e\u6216\u5faa\u73af\u65f6\u52a8\u753b\u5c06\u7ed3\u675f\u7684\u6700\u5927\u5e27\u3002 \u8be5\u503c\u5c06\u88ab\u94b3\u5236\u5230\u5408\u6210\u8fb9\u754c\u3002\u4f8b\u5982\uff0c\u8bbe\u7f6e\u6574\u6570\u6700\u5927\u503c\u5c06\u4ea7\u751f\u4e0e\u5408\u6210\u76f8\u540c\u7684\u7ed3\u679c\u3002 \u901a\u8fc7float getMaxFrame()\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u8bbe\u5b9a\u7684\u6700\u5927\u5e27<\/p>\n void setMinFrame(int startFrame) \u8bbe\u7f6e\u64ad\u653e\u6216\u5faa\u73af\u65f6\u52a8\u753b\u5f00\u59cb\u7684\u6700\u5c0f\u5e27\u3002 \u8bbe\u5b9a\u6700\u5927\u3001\u6700\u5c0f\u5e27\u53ef\u4ee5\u53ea\u64ad\u653elottie\u52a8\u753b\u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u4f8b\u5982\u4e0b\u9762\u7684\u4e24\u5f20\u56fe\uff0c\u7b2c\u4e00\u5f20\u662f\u5b8c\u6574\u7684\u4ece0\u64ad\u653e\u5230183\u5e27\uff0c\u7b2c\u4e8c\u5f20\u5219\u662f\u4ece60\u64ad\u653e\u5230100\u5e27\u3002<\/p>\n lottie_progress \u8bbe\u5b9a\u52a8\u753b\u521d\u6b21\u663e\u793a\u65f6\u7684\u8fdb\u5ea6\uff0c\u7c7b\u578b\u4e3afloat\u3002\u53d6\u503c\u8303\u56f40.0 ~ 1.0 void setProgress(@FloatRange(from = 0f, to = 1f) float progress) float getProgress()<\/p>\n lottie_speed \u8bbe\u5b9a\u64ad\u653e\u901f\u5ea6\uff0c\u53d6\u503c\u7c7b\u578b\u4e3afloat\u3002\u5f53\u901f\u5ea6<1\u65f6\uff0c\u52a8\u753b\u4f1a\u6162\u653e\uff0c\u5f53\u901f\u5ea6<0\u65f6\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5012\u5e8f\u64ad\u653e\u3002 void setSpeed(float speed) float getSpeed() void reverseAnimationSpeed()\uff1a\u53cd\u8f6c\u5f53\u524d\u52a8\u753b\u901f\u5ea6\u3002\u8fd9\u4e0d\u4f1a\u64ad\u653e\u52a8\u753b\u3002<\/p>\n \u901f\u5ea6\u662f\u4e00\u4e2a\u6bd4\u8f83\u91cd\u8981\u7684\u5c5e\u6027\uff0c\u4e0eprogress\u3001frame\u7b49\u5c5e\u6027\u4e00\u8d77\u7075\u6d3b\u8fd0\u7528\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u8f7b\u677e\u5730\u5728HMI\u4e0a\u5b9e\u73b0\u70ab\u9177\u800c\u590d\u6742\u7684\u4eea\u8868\u76d8\u6548\u679c\uff0c\u8fd9\u5bf9\u8f66\u8f7dHMI\u5c24\u4e3a\u91cd\u8981\u3002<\/p>\n lottie_enableMergePathsForKitKatAndAbove \u8bbe\u5b9a\u662f\u5426\u5f00\u542fMergePath\u5c5e\u6027\uff0c\u53d6\u503c\u4e3atrue | false\u3002\u9ed8\u8ba4\u4e3afalse void enableMergePathsForKitKatAndAbove(boolean enable) boolean isMergePathsEnabledForKitKatAndAbove()<\/p>\n void playAnimation() \u4ece\u5934\u5f00\u59cb\u64ad\u653e\u52a8\u753b\u3002\u5982\u679c\u901f\u5ea6<0\uff0c\u5b83\u5c06\u4ece\u7ec8\u70b9\u5f00\u59cb\uff0c\u5e76\u5411\u8d77\u70b9\u64ad\u653e\u3002\u5fc5\u987b\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u8c03\u7528\u3002<\/p>\n void cancelAnimation() \u53d6\u6d88\u52a8\u753b\uff0c\u5fc5\u987b\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u8c03\u7528\u3002<\/p>\n void pauseAnimation() \u6682\u505c\u52a8\u753b\uff0c\u5fc5\u987b\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u8c03\u7528\u3002<\/p>\n void resumeAnimation() \u4ece\u5f53\u524d\u4f4d\u7f6e\u7ee7\u7eed\u64ad\u653e\u52a8\u753b\u3002\u5982\u679c\u901f\u5ea6<0\uff0c\u5b83\u5c06\u4ece\u5f53\u524d\u4f4d\u7f6e\u5411\u540e\u64ad\u653e\u3002\u5fc5\u987b\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u8c03\u7528\u3002<\/p>\n long getDuration() \u83b7\u53d6\u52a8\u753b\u7684\u64ad\u653e\u65f6\u957f\u3002<\/p>\n void setTextDelegate(TextDelegate textDelegate) \u8bbe\u7f6e\u6b64\u9009\u9879\u53ef\u5728\u8fd0\u884c\u65f6\u7528\u81ea\u5b9a\u4e49\u6587\u672c\u66ff\u6362\u52a8\u753b\u6587\u672c<\/p>\n lottie_cacheComposition \u8bbe\u5b9a\u662f\u5426\u5f00\u542f\u7f13\u5b58\uff0c\u53d6\u503c true | false\uff0c\u9ed8\u8ba4\u5f00\u542f\u3002\u5f00\u542f\u7f13\u5b58\u53ef\u4ee5\u63d0\u5347\u52a8\u753b\u7684\u52a0\u8f7d\u6548\u7387\u3002<\/p>\n \u76d1\u542clottie\u52a8\u753bjson\u4e2d\u67d0\u4e2a\u7247\u6bb5\u7684\u5c5e\u6027\u3002<\/p>\n \u6b64<\/p>\n keypath<\/p>\n \u53ef\u4ee5\u89e3\u6790\u4e3a\u591a\u4e2a\u5185\u5bb9\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u56de\u8c03\u7684\u503c\u5c06\u5e94\u7528\u4e8e\u6240\u6709\u56de\u8c03\u3002\u5728\u5185\u90e8\u4f1a\u9996\u5148\u68c0\u67e5\u662f\u5426\u5df2\u4f7f\u7528resolveKeyPath\uff08KeyPath\uff09\u89e3\u6790keypath\uff0c\u5982\u679c\u5c1a\u672a\u89e3\u6790\uff0c\u5219\u5c06\u5bf9\u5176\u8fdb\u884c\u89e3\u6790\u3002<\/p>\n Lottie\u52a8\u753b\u7684Json\u4e2d\u5c5e\u6027\u90fd\u662f\u82f1\u6587\u7b80\u5199\uff0c\u6211\u4eec\u5f88\u96be\u628ajson\u4e2dkey\u4e0e\u5b9e\u9645\u7684\u5c5e\u6027\u5bf9\u5e94\u8d77\u6765\uff0c\u6240\u4ee5\u6709\u4e86\u7b2c\u4e8c\u4e2a\u53c2\u6570<\/p>\n LottieProperty<\/p>\n \uff0c\u5b83\u7684\u5185\u90e8\u5b9a\u4e49\u4e86\u5927\u91cf\u7684\u5c5e\u6027\uff0c\u5f53\u6211\u4eec\u9700\u8981\u4fee\u6539json\u65f6\uff0c\u53ea\u9700\u8981\u4f20\u5165<\/p>\n LottieProperty<\/p>\n \u4e2d\u5c5e\u6027\u5373\u53ef\u3002<\/p>\n \u4f8b\u5982\uff0c\u9700\u8981\u76d1\u542cjson\u4e2d<\/p>\n LeftArmWave<\/p>\n \u7684\u6301\u7eed\u65f6\u95f4\uff0c\u5c31\u53ef\u4ee5\u8fd9\u4e48\u5199<\/p>\n Lottie\u7684Demo\u4e2d\u5185\u7f6e\u4e86\u5f88\u591a\u5b98\u65b9\u81ea\u5df1\u5f00\u53d1\u7684\u52a8\u753b\u6548\u679c\uff0c\u76ee\u7684\u662f\u4e3a\u6211\u4eec\u5c55\u793aLottie\u7684\u5e38\u89c1\u7528\u6cd5\uff0c\u4f5c\u4e3a\u5f00\u53d1\u8005\u6211\u4eec\u5fc5\u987b\u638c\u63e1\uff0c\u5e76\u5728\u9002\u5f53\u7684\u65f6\u5019\u8fd0\u7528\u5230\u6211\u4eec\u7684\u5e94\u7528\u4e2d\u3002<\/p>\n \u8be5\u6548\u679c\u5c55\u793a\u4e86lottie\u652f\u6301\u52a8\u6001\u4fee\u6539json\uff0c\u8ba9\u52a8\u753b\u4e2d\u7684\u4e00\u5c0f\u90e8\u5206\u5c5e\u6027\u53d1\u751f\u6539\u53d8\u3002<\/p>\u4fee\u6539\u5c40\u90e8\u52a8\u753b\u7684\u901f\u5ea6 KeyPath\u4e2d\u7684LeftArmWave\u662fJson\u4e2d\u7684\u4e00\u4e2a\u5c5e\u6027<\/p>\n \u4fee\u6539\u7684\u6548\u679c\u5982\u4e0b\u3002\u6ce8\u610f\u770b\u53f3\u624b\u7684\u6446\u52a8\u9891\u7387X3\u540e\u6bd4X1\u9ad8\uff0c\u4ee5\u81f3\u4e8e\u5f55\u5236\u7684GIF\u76f4\u63a5\u4e22\u5e27\u4e86\u3002<\/p>\n \u4fee\u6539\u540e\u7684\u6548\u679c\u5982\u4e0b<\/p>\n Lottie\u5728\u8f66\u8f7dHMI\u4e2d\u7684\u4f18\u52bf<\/h3>\n
Lottie\u7684\u4f7f\u7528\u65b9\u6cd5<\/h3>\u5728build.gradle\u4e2d\u6dfb\u52a0\u4f9d\u8d56
3.Lottie\u7684\u5e38\u7528\u5c5e\u6027&API<\/h3>\n
4.Lottie\u7684\u5e38\u89c1\u7528\u6cd5<\/h3>\n
\u52a8\u6001\u5c5e\u6027\u6548\u679c<\/h3>\n