{"id":947,"date":"2023-03-11T18:55:34","date_gmt":"2023-03-11T10:55:34","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=947"},"modified":"2023-04-29T15:30:00","modified_gmt":"2023-04-29T07:30:00","slug":"android-tablayout-tab-layout-stretch-animation","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/11\/android-tablayout-tab-layout-stretch-animation\/","title":{"rendered":"Android TabLayout\u9009\u9879\u5361Tab\u5e03\u5c40\u4f38\u7f29\u52a8\u753b"},"content":{"rendered":"<p>\u9700\u6c42\uff1a\u5f53ScrollView\u4e0a\u6ed1\u65f6\uff0c\u52a8\u753b\u6536\u7f29\u9690\u85cfTab\uff1b\u5f53ScrollView\u4e0b\u62c9\u65f6\uff0c\u52a8\u753b\u6269\u5c55\u663e\u793aTab<\/p>\n<p>\u65b9\u6848\uff1aValueAnimator\u5c5e\u6027\u52a8\u753b\u6539\u53d8TabLayout\u7684\u9ad8\u5ea6<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">private ValueAnimator mGoodsTabIndentAnimator;\nprivate ValueAnimator mGoodsTabExpandAnimator;\nprivate int mGoodsTabLayoutHeight;\n\npublic void startGoodsTabIndentAnimation() {\n    if (mGoodsTabIndentAnimator == null) {\n        mGoodsTabLayoutHeight = mGoodsTabLayout.getHeight();\n        NLog.i(TAG, &quot;mGoodsTabLayout Height: &quot; + mGoodsTabLayoutHeight);\n        mGoodsTabIndentAnimator = ValueAnimator.ofInt(mGoodsTabLayout.getHeight(), 0);\n        mGoodsTabIndentAnimator.setDuration(200);\n        mGoodsTabIndentAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {\n            @Override\n            public void onAnimationUpdate(ValueAnimator valueAnimator) {\n                Integer value = (Integer) valueAnimator.getAnimatedValue();\n                ViewGroup.LayoutParams params = mGoodsTabLayout.getLayoutParams();\n                params.height = value;\n                mGoodsTabLayout.setLayoutParams(params);\n            }\n        });\n    }\n    mGoodsTabIndentAnimator.start();\n}\n\npublic void startGoodsTabExpandAnimation() {\n    if (mGoodsTabExpandAnimator == null) {\n        mGoodsTabExpandAnimator = ValueAnimator.ofInt(0, mGoodsTabLayoutHeight);\n        mGoodsTabExpandAnimator.setDuration(200);\n        mGoodsTabExpandAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {\n            @Override\n            public void onAnimationUpdate(ValueAnimator valueAnimator) {\n                Integer value = (Integer) valueAnimator.getAnimatedValue();\n                ViewGroup.LayoutParams params = mGoodsTabLayout.getLayoutParams();\n                params.height = value;\n                mGoodsTabLayout.setLayoutParams(params);\n            }\n        });\n    }\n    mGoodsTabExpandAnimator.start();\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42\uff1a\u5f53ScrollView\u4e0a\u6ed1\u65f6\uff0c\u52a8\u753b\u6536\u7f29\u9690\u85cfTab\uff1b\u5f53ScrollView\u4e0b\u62c9\u65f6\uff0c\u52a8\u753b\u6269\u5c55\u663e\u793aTab \u65b9\u6848 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[119],"tags":[258],"class_list":["post-947","post","type-post","status-publish","format-standard","hentry","category-android-ui","tag-tablayout"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/947","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=947"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/947\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}