最近在项目中使用到了CoordinatorLayout和AppBarLayout,主要是为了实现当向上滑动的时候顶部部分布局隐藏,但是对于下方布局是RecycleView时没有问题,但是我们下方使用的是TabLayout+ViewPager,并且Fragment中使用的是WebView.
在正常使用的情况下,我们会在WebView外层嵌套NestedScrollView来配合CoordinatorLayout使用。但是用一种特殊情况:H5页面中如果有悬浮控件,悬浮控件会丢失位置。
其根本原因是:WebView在谷歌的材料设计库中并不支持CoordinatorLayout滚动技术,也就是说CoordinatorLayout不支持和WebView协同使用。
解决办法:
1、在WebView外层套上NestedScrollView
这样处理虽然简单,但是可能导致WebView中的某些JS方法无法使用。
2、重写WebView实现NestedScrollingChild
/**
* NestedScrollWebView to
*/
public class NestedScrollWebView extends WebView implements NestedScrollingChild {
public static final String TAG = NestedScrollWebView.class.getSimpleName();
private int mLastMotionY;
private final int[] mScrollOffset = new int[2];
private final int[] mScrollConsumed = new int[2];
private int mNestedYOffset;
private NestedScrollingChildHelper mChildHelper;
public NestedScrollWebView(Context context) {
super(context);
init();
}
public NestedScrollWebView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public NestedScrollWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();

最低0.47元/天 解锁文章
6091

被折叠的 条评论
为什么被折叠?



