Created
September 14, 2015 09:44
-
-
Save brucetoo/e494e6b6ab0f14b9789e to your computer and use it in GitHub Desktop.
ViewPager滚动时关闭硬件渲染(特别在ViewPager切换定义了动画时)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
特别是在定义了 PageTransformer 来实现Page之间的切换动画 | |
会调用到ViewPaper#setScrollState() -> 然后再调用 ViewPager#enableLayers() | |
默认就开启了硬件加速,因此在动画执行过程中,会预先执行硬件加速,可能就导致了View动画执行的时候掉帧 | |
可以开启 Show HardWare layers updates 来锁定开启硬件加速的View | |
//以下是解决办法 | |
@Override | |
public void onPageScrollStateChanged(int scrollState) { | |
// A small hack to remove the HW layer that the viewpager add to each page when scrolling. | |
if (scrollState != ViewPager.SCROLL_STATE_IDLE) { | |
final int childCount = <your_viewpager>.getChildCount(); | |
for (int i = 0; i < childCount; i++) | |
<your_viewpager>.getChildAt(i).setLayerType(View.LAYER_TYPE_NONE, null); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment