{"id":726,"date":"2023-02-26T15:36:52","date_gmt":"2023-02-26T07:36:52","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=726"},"modified":"2023-04-29T17:12:43","modified_gmt":"2023-04-29T09:12:43","slug":"best-practices-for-loading-gif-maps-on-android","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/best-practices-for-loading-gif-maps-on-android\/","title":{"rendered":"Android \u52a0\u8f7dGIF\u56fe\u6700\u4f73\u5b9e\u8df5\u65b9\u6848"},"content":{"rendered":"<p>Github\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/koral--\/android-gif-drawable\">https:\/\/github.com\/koral&#8211;\/android-gif-drawable<\/a><\/p>\n<p>\u6dfb\u52a0\u4f9d\u8d56\uff1a<\/p>\n<pre><code>implementation &#039;pl.droidsonroids.gif:android-gif-drawable:1.2.18&#039;<\/code><\/pre>\n<p><!-- more --><\/p>\n<p>\u76f4\u63a5\u628a\u5e03\u5c40\u6587\u4ef6\u4e2d\u7684 ImageView \u66ff\u6362\u4e3a GifImageView<\/p>\n<pre><code class=\"language-xml\">&lt;pl.droidsonroids.gif.GifImageView\n    android:layout_width=&quot;match_parent&quot;\n    android:layout_height=&quot;match_parent&quot;\n    android:src=&quot;@mipmap\/appblog&quot;\n    \/&gt;<\/code><\/pre>\n<p>\u4ee3\u7801\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"language-java\">GifImageView gifImageView = (GifImageView) findViewById(R.id.gifImageView);\nGifDrawable gifDrawable = (GifDrawable) gifImageView.getDrawable();<\/code><\/pre>\n<p>\u6839\u636e\u9700\u8981\u8c03\u7528\u4ee5\u4e0b\u65b9\u6cd5\u5373\u53ef\uff0c\u6548\u679c\u8fd8\u4e0d\u9519\uff0c\u5f88\u6d41\u7545<\/p>\n<pre><code class=\"language-java\">gifDrawable.start();  \/\/\u5f00\u59cb\u64ad\u653e\ngifDrawable.stop();  \/\/\u505c\u6b62\u64ad\u653e\ngifDrawable.reset();  \/\/\u590d\u4f4d\uff0c\u91cd\u65b0\u5f00\u59cb\u64ad\u653e\ngifDrawable.isRunning();  \/\/\u662f\u5426\u6b63\u5728\u64ad\u653e\ngifDrawable.setLoopCount( 2 );  \/\/\u8bbe\u7f6e\u64ad\u653e\u7684\u6b21\u6570\uff0c\u64ad\u653e\u5b8c\u4e86\u5c31\u81ea\u52a8\u505c\u6b62\ngifDrawable.getCurrentLoop()\uff1b \/\/\u83b7\u53d6\u6b63\u5728\u64ad\u653e\u7684\u6b21\u6570\ngifDrawable.getCurrentPosition;  \/\/\u83b7\u53d6\u73b0\u5728\u5230\u4ece\u5f00\u59cb\u64ad\u653e\u6240\u7ecf\u5386\u7684\u65f6\u95f4\ngifDrawable.getDuration();  \/\/\u83b7\u53d6\u64ad\u653e\u4e00\u6b21\u6240\u9700\u8981\u7684\u65f6\u95f4<\/code><\/pre>\n<p>\u603b\u7ed3\uff1a\u5c1d\u8bd5\u7528Glide \u5b9e\u73b0\uff0c\u4f46\u662f\u6548\u679c\u4e0d\u662f\u4e0d\u597d\uff0c\u5361\u987f\uff0c\u7136\u540e\u53d1\u73b0\u4f9d\u8d56\u8fd9\u4e2ajar\u540e\uff0c\u6548\u679c\u4e0d\u9519\uff0c\u4e14jar\u4e5f\u4e0d\u662f\u5f88\u5927\uff0c\u4e5f\u5c3175k<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Github\uff1ahttps:\/\/github.com\/koral&#8211;\/android-gif-draw [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[206],"tags":[215],"class_list":["post-726","post","type-post","status-publish","format-standard","hentry","category-android-image-loader","tag-gif"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=726"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/726\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}