{"id":21234,"date":"2024-11-19T08:12:26","date_gmt":"2024-11-19T00:12:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/21234\/"},"modified":"2024-11-19T08:12:26","modified_gmt":"2024-11-19T00:12:26","slug":"composer%e6%80%8e%e4%b9%88%e7%94%a8%e8%a7%86%e5%9b%be%e5%81%9a%e5%8a%a8%e7%94%bb","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/21234\/","title":{"rendered":"composer\u600e\u4e48\u7528\u89c6\u56fe\u505a\u52a8\u753b"},"content":{"rendered":"<blockquote><p>\n  \u5728 jetpack compose \u4e2d\u4f7f\u7528\u89c6\u56fe\u5b9e\u73b0\u52a8\u753b\uff0c\u5305\u62ec\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u521b\u5efa\u52a8\u753b\u89c6\u56fe\uff08\u4f8b\u5982 animatedvisibility\u3001animatedcontent \u6216 animatedtransform\uff09\u3002\u4f7f\u7528\u8fc7\u6e21 api\uff08\u4f8b\u5982 crossfade\u3001slide\u3001scale\u3001fade\uff09\u521b\u5efa\u8fc7\u6e21\u6548\u679c\u3002\u901a\u8fc7 targetstate \u548c modifier \u5c5e\u6027\u8bbe\u7f6e\u52a8\u753b\u5c5e\u6027\u3002\u901a\u8fc7 animatecontentsize \u6216 animateasstate \u51fd\u6570\u5b9e\u73b0\u5e73\u6ed1\u7684\u52a8\u753b\u3002\u4f7f\u7528 stateflow \u6216 flow\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/09\/2024040913572024245.jpg\" class=\"aligncenter\" title=\"composer\u600e\u4e48\u7528\u89c6\u56fe\u505a\u52a8\u753b\u63d2\u56fe\" alt=\"composer\u600e\u4e48\u7528\u89c6\u56fe\u505a\u52a8\u753b\u63d2\u56fe\" \/><\/p>\n<p><strong>Composer \u4e2d\u4f7f\u7528\u89c6\u56fe\u5b9e\u73b0\u52a8\u753b<\/strong><\/p>\n<p>\u5728 Jetpack Compose \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u89c6\u56fe\u521b\u5efa\u5e73\u6ed1\u3001\u54cd\u5e94\u5f0f\u7684\u52a8\u753b\u6548\u679c\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528\u89c6\u56fe\u8fdb\u884c\u52a8\u753b\uff1a<\/p>\n<p><strong>\u521b\u5efa\u52a8\u753b\u89c6\u56fe<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a AnimatedVisibility\u3001AnimatedContent \u6216 AnimatedTransform \u89c6\u56fe\u4ee5\u5305\u88f9\u8981\u8fdb\u884c\u52a8\u753b\u7684\u5b50\u89c6\u56fe\u3002\u8fd9\u4e9b\u89c6\u56fe\u63d0\u4f9b\u52a8\u753b\u5c5e\u6027\uff0c\u4f8b\u5982 visibility \u548c modifier\u3002<\/p>\n<p><strong>\u4f7f\u7528\u8fc7\u6e21<\/strong><\/p>\n<p>\u4f7f\u7528 Transition API \u5728\u89c6\u56fe\u72b6\u6001\u4e4b\u95f4\u521b\u5efa\u8fc7\u6e21\u6548\u679c\u3002\u5e38\u7528\u7684\u8fc7\u6e21\u6709\uff1a<\/p>\n<ul>\n<li>Crossfade\uff1a\u6de1\u5165\u6de1\u51fa<\/li>\n<li>Slide\uff1a\u5e73\u79fb<\/li>\n<li>Scale\uff1a\u7f29\u653e<\/li>\n<li>Fade\uff1a\u6de1\u5165\u6de1\u51fa<\/li>\n<\/ul>\n<p><strong>\u8bbe\u7f6e\u52a8\u753b\u5c5e\u6027<\/strong><\/p>\n<p>\u901a\u8fc7 targetState \u548c modifier \u5c5e\u6027\u8bbe\u7f6e\u89c6\u56fe\u7684\u52a8\u753b\u5c5e\u6027\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>AnimatedVisibility(\n    visible = visible,\n    enter = scaleIn(),\n    exit = fadeOut()\n) {\n    Text(\"Hello, World!\")\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5b9e\u73b0\u8fc7\u6e21<\/strong><\/p>\n<p>\u901a\u8fc7 animateContentSize \u6216 animateAsState \u51fd\u6570\u5728\u89c6\u56fe\u72b6\u6001\u4e4b\u95f4\u5b9e\u73b0\u5e73\u6ed1\u7684\u52a8\u753b\u3002\u524d\u8005\u7528\u4e8e\u8c03\u6574\u89c6\u56fe\u5927\u5c0f\uff0c\u800c\u540e\u8005\u7528\u4e8e\u66f4\u6539\u89c6\u56fe\u5185\u5bb9\u3002<\/p>\n<p><strong>\u5904\u7406\u52a8\u753b\u4e8b\u4ef6<\/strong><\/p>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 StateFlow \u6216 Flow \u76d1\u542c\u52a8\u753b\u4e8b\u4ef6\uff0c\u4f8b\u5982\u52a8\u753b\u662f\u5426\u5f00\u59cb\u3001\u7ed3\u675f\u6216\u53d6\u6d88\u3002\u8fd9\u6709\u52a9\u4e8e\u5728\u52a8\u753b\u8fc7\u7a0b\u4e2d\u66f4\u65b0 UI \u6216\u89e6\u53d1\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a\u5e73\u79fb\u52a8\u753b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u4f7f\u7528\u89c6\u56fe\u521b\u5efa\u5e73\u6ed1\u7684\u5e73\u79fb\u52a8\u753b\uff1a<\/p>\n<pre>var offsetX = remember { mutableStateOf(0f) }\n\nColumn {\n    Button(onClick = { offsetX.value = 100f }) {\n        Text(\"Move\")\n    }\n\n    Spacer(modifier = Modifier.width(offsetX.value))\n    Text(\"Hello, World!\")\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728 AnimatedVisibility \u548c AnimatedContent \u89c6\u56fe\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 initialVisibility \u5c5e\u6027\u6307\u5b9a\u521d\u59cb\u53ef\u89c1\u6027\u3002<\/li>\n<li>AnimatedTransform \u89c6\u56fe\u63d0\u4f9b pivot \u5c5e\u6027\uff0c\u8be5\u5c5e\u6027\u5b9a\u4e49\u6cbf\u5176\u65cb\u8f6c\u6216\u7f29\u653e\u7684\u89c6\u56fe\u4e2d\u5fc3\u70b9\u3002<\/li>\n<li>\u786e\u4fdd\u52a8\u753b\u5c5e\u6027\u7684\u503c\u4e0e\u89c6\u56fe\u7684\u5b9e\u9645\u72b6\u6001\u540c\u6b65\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u7528\u89c6\u56fe\u505a\u52a8\u753b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 jetpack compose \u4e2d\u4f7f\u7528\u89c6\u56fe\u5b9e\u73b0\u52a8\u753b\uff0c\u5305\u62ec\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u521b\u5efa\u52a8\u753b\u89c6\u56fe\uff08\u4f8b\u5982 animatedvisibility\u3001animatedcontent \u6216 animatedtransform\uff09\u3002\u4f7f\u7528\u8fc7\u6e21 api\uff08\u4f8b\u5982 crossfade\u3001slide\u3001scale\u3001fade\uff09\u521b\u5efa\u8fc7\u6e21\u6548\u679c\u3002\u901a\u8fc7 targetstate \u548c modifier \u5c5e\u6027\u8bbe\u7f6e\u52a8\u753b\u5c5e\u6027\u3002\u901a\u8fc7 animatecontentsize \u6216 animateasstate \u51fd\u6570\u5b9e\u73b0\u5e73\u6ed1\u7684\u52a8\u753b\u3002\u4f7f\u7528 stateflow \u6216 flow Composer \u4e2d\u4f7f\u7528\u89c6\u56fe\u5b9e\u73b0\u52a8\u753b \u5728 Jetpack Compose \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u89c6\u56fe\u521b\u5efa\u5e73\u6ed1\u3001\u54cd\u5e94\u5f0f\u7684\u52a8\u753b\u6548\u679c\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528\u89c6\u56fe\u8fdb\u884c\u52a8\u753b\uff1a \u521b\u5efa\u52a8\u753b\u89c6\u56fe \u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a AnimatedVisibility\u3001AnimatedContent \u6216 AnimatedTransform \u89c6\u56fe\u4ee5\u5305\u88f9\u8981\u8fdb\u884c\u52a8\u753b\u7684\u5b50\u89c6\u56fe\u3002\u8fd9\u4e9b\u89c6\u56fe\u63d0\u4f9b\u52a8\u753b\u5c5e\u6027\uff0c\u4f8b\u5982 visibility \u548c modifier\u3002 \u4f7f\u7528\u8fc7\u6e21 \u4f7f\u7528 Transition API \u5728\u89c6\u56fe\u72b6\u6001\u4e4b\u95f4\u521b\u5efa\u8fc7\u6e21\u6548\u679c\u3002\u5e38\u7528\u7684\u8fc7\u6e21\u6709\uff1a Crossfade\uff1a\u6de1\u5165\u6de1\u51fa Slide\uff1a\u5e73\u79fb Scale\uff1a\u7f29\u653e Fade\uff1a\u6de1\u5165\u6de1\u51fa \u8bbe\u7f6e\u52a8\u753b\u5c5e\u6027 \u901a\u8fc7 targetState \u548c modifier \u5c5e\u6027\u8bbe\u7f6e\u89c6\u56fe\u7684\u52a8\u753b\u5c5e\u6027\u3002\u4f8b\u5982\uff1a AnimatedVisibility( visible = visible, enter [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-21234","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=21234"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21234\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=21234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=21234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=21234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}