Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

默认设置退出动画会内存泄漏 #117

Closed
MyMoonCat opened this issue Aug 11, 2019 · 7 comments
Closed

默认设置退出动画会内存泄漏 #117

MyMoonCat opened this issue Aug 11, 2019 · 7 comments

Comments

@MyMoonCat
Copy link

MyMoonCat commented Aug 11, 2019

退出时会偶现内存泄漏 看源码发现是退出动画时长问题

首先看默认动画时长
/** * 初始化数据 */ private void initData() { imgUrls = getIntent().getParcelableArrayListExtra("imagePaths"); currentIndex = getIntent().getIntExtra("position", -1); type = (GPreviewBuilder.IndicatorType) getIntent().getSerializableExtra("type"); isShow = getIntent().getBooleanExtra("isShow", true); int duration = getIntent().getIntExtra("duration", 300);

这里默认动画时长是300ms ,这里的动画时长是SmoothImageView的动画

/***退出预览的动画***/ public void transformOut() { if (isTransformOut) { return; } getViewPager().setEnabled(false); isTransformOut = true; int currentItem = viewPager.getCurrentItem(); if (currentItem < imgUrls.size()) { BasePhotoFragment fragment = fragments.get(currentItem); if (ltAddDot != null) { ltAddDot.setVisibility(View.GONE); } else { bezierBannerView.setVisibility(View.GONE); } fragment.changeBg(Color.TRANSPARENT); fragment.transformOut(new SmoothImageView.onTransformListener() { @Override public void onTransformCompleted(SmoothImageView.Status status) { getViewPager().setEnabled(true); exit(); } }); } else { exit(); } }

退出动画会调用fragment的changeBg动画,再去看看这个动画时长
public void changeBg(int color) { ViewCompat.animate(btnVideo).alpha(0).setDuration(500).start(); rootView.setBackgroundColor(color); }

哦豁,这里是500ms, exit();的执行时间是transformOut的动画完成后,transformOut的动画时长就是上面的300ms。exit();里执行了activity的finish()
所以这里调用activity的finish()时changeBg的动画没有执行完成导致内存泄漏。

@yangchaojiang
Copy link
Owner

transformOut 动画改成500ms 要改都改哦

@MyMoonCat
Copy link
Author

transformOut动画改成500ms要改都改哦

transformOut动画改成500ms的实际体验不好,还是把changeBg的动画时长统一一下好点,所有动画共用一个duration

@yangchaojiang
Copy link
Owner

不能。有的动画, 不需要那么长的,各有适合动画

@MyMoonCat
Copy link
Author

不能。有的动画, 不需要那么长的,各有适合动画

那要在finish前停止掉所有动画,不然很容易内存泄漏

@yangchaojiang
Copy link
Owner

我看看 改成同意时长 对动画过渡斯时候有影响, 没有我可以改一下

@yangchaojiang
Copy link
Owner

2.2.5 版本

@MyMoonCat
Copy link
Author

2.2.5 版本

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants