Scroll doesn't work in NestedScrollView when try to scroll from views with click events

前端 未结 4 1023
时光说笑
时光说笑 2020-12-24 07:19

I\'m using a NestedScrollView in a layout, and am attempting to use the new CoordinatorLayout from the design support library for CollapsingToolbarLayout.

My layout

4条回答
  •  孤城傲影
    2020-12-24 07:29

    I had the same problem. It happens only when NestedScrollView content height is less than height of device screen. So the workaround is to use setMinimumHeight(..) method for the view inside your NestedScrollView to make it resize to screen height:

    DisplayMetrics displaymetrics = new DisplayMetrics();
    getBaseActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int screenHeight = displaymetrics.heightPixels;
    
    int actionBarHeight = 0;
    TypedValue tv = new TypedValue();
    if (getBaseActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
    }
    
    view.setMinimumHeight(screenHeight - actionBarHeight);
    

    where view is your RelativeLayout

    It works fine fore me. Hope it helps you

提交回复
热议问题