VerticalViewPager
VerticalViewPager copied to clipboard
有一个小的问题,当在Fragment添加SurfaceView的时候,出现的
我遇到的问题是,Fragment添加SurfaceView,触摸屏幕的时候,会造成一个问题 SurfaceView 会被隐藏,显示出底部背景, 从而造成闪现背景, 最后我发现 其实子页并非在最上面,所以触摸事件被隐藏在其上面的View给消费了,我的解决方案是在VerticalViewPager中重写onPageScrolled和setPageTransformer, 下面是我的解决方案的源码 ` @Override protected void onPageScrolled(int position, float offset, int offsetPixels) { super.onPageScrolled(position, offset, offsetPixels); // 下面的源码来自super.onPageScrolled() int scrollX; int childCount; int i; if (this.mPageTransformer != null) { scrollX = this.getScrollX(); childCount = this.getChildCount();
for (i = 0; i < childCount; ++i) {
View var15 = this.getChildAt(i);
ViewPager.LayoutParams var16 = (ViewPager.LayoutParams) var15.getLayoutParams();
if (!var16.isDecor) {
float var17 = (float) (var15.getLeft() - scrollX) / (float) this.getClientWidth();
this.mPageTransformer.transformPage(var15, var17);
}
}
}
}
private int getClientWidth() {
return this.getMeasuredWidth() - this.getPaddingLeft() - this.getPaddingRight();
}
@Override
public void setPageTransformer(boolean reverseDrawingOrder, ViewPager.PageTransformer transformer) {
super.setPageTransformer(reverseDrawingOrder, null);
mPageTransformer = transformer;
}`