Android TabLayout选项卡Tab布局伸缩动画
需求:当ScrollView上滑时,动画收缩隐藏Tab;当ScrollView下拉时,动画扩展显示Tab
方案:ValueAnimator属性动画改变TabLayout的高度
private ValueAnimator mGoodsTabIndentAnimator;
private ValueAnimator mGoodsTabExpandAnimator;
private int mGoodsTabLayoutHeight;
public void startGoodsTabIndentAnimation() {
if (mGoodsTabIndentAnimator == null) {
mGoodsTabLayoutHeight = mGoodsTabLayout.getHeight();
NLog.i(TAG, "mGoodsTabLayout Height: " + mGoodsTabLayoutHeight);
mGoodsTabIndentAnimator = ValueAnimator.ofInt(mGoodsTabLayout.getHeight(), 0);
mGoodsTabIndentAnimator.setDuration(200);
mGoodsTabIndentAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
Integer value = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams params = mGoodsTabLayout.getLayoutParams();
params.height = value;
mGoodsTabLayout.setLayoutParams(params);
}
});
}
mGoodsTabIndentAnimator.start();
}
public void startGoodsTabExpandAnimation() {
if (mGoodsTabExpandAnimator == null) {
mGoodsTabExpandAnimator = ValueAnimator.ofInt(0, mGoodsTabLayoutHeight);
mGoodsTabExpandAnimator.setDuration(200);
mGoodsTabExpandAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
Integer value = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams params = mGoodsTabLayout.getLayoutParams();
params.height = value;
mGoodsTabLayout.setLayoutParams(params);
}
});
}
mGoodsTabExpandAnimator.start();
}
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/11/android-tablayout-tab-layout-stretch-animation/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
Android TabLayout选项卡Tab布局伸缩动画
需求:当ScrollView上滑时,动画收缩隐藏Tab;当ScrollView下拉时,动画扩展显示Tab
方案:ValueAnimator属性动画改变TabLayout的高度
private ValueAnimator……
文章目录
关闭
共有 0 条评论