Jude95 / SwipeBackHelper

make your activity can swipe to close
1.38k stars 268 forks source link

requestLayout()导致仿微信的联动动画失效 #61

Open myt386289635 opened 7 years ago

myt386289635 commented 7 years ago

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { final ScrollView scrollView = (ScrollView) findViewById(R.id.sv_data); final View decorView = getWindow().getDecorView(); decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect rect = new Rect(); decorView.getWindowVisibleDisplayFrame(rect); int screenHeight = decorView.getRootView().getHeight(); int heightDifference = screenHeight - rect.bottom;//计算软键盘占有的高度 = 屏幕高度 - 视图可见高度 LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) scrollView.getLayoutParams(); layoutParams.setMargins(0, 0, 0, heightDifference);//设置ScrollView的marginBottom的值为软键盘占有的高度即可 scrollView.requestLayout(); } }); }

这是解决透明状态栏导致软件盘弹出后,ScrollView滑动失效的问题。 加了这段代码以后,我发现放微信效果的联动动画失效了。其他页都是正常的,就打开这种页面动画就消失了。经过一番测试,我发现是scrollView.requestLayout();这句话导致动画消失的,想请教一下作者,这个问题怎么解决?