滚动坐标仪时,当内部循环系统处于第一个位置并将其拉下时



我有一个以下布局的活动。

<android.support.design.widget.CoordinatorLayout>
    <View/>
    <FrameLayout
    android:id="@+id/fragment_container"
    app:layout_behavior="@string/bottom_sheet_behavior"/>
</android.support.design.widget.CoordinatorLayout>

我的片段包含垂直循环系统。这充当了另一个回收即可滚动的容器。片段布局是:

<RelativeLayout>
<android.support.v7.widget.RecyclerView
    android:id="@+id/wall_rooms"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="@dimen/app_bar_height"
    android:background="@color/pinkDark"
    android:overScrollMode="never" />
</RelativeLayout>

当recyclerview在顶部显示第一个项目,而用户向下显示回收器视图时,协调器布局应滚动内容。如果recyclerview正在显示其他项目,则向下滚动应滚动回收库的内容。

我尝试使用setNestedScrollingEnabled = false,但是RecyClerview中的项目不滚动。

在花费大量时间之后,尝试不同的事情,最终使它起作用。扩展了底部表贝哈维尔类,并在Intercepttouchevent方法上覆盖了它。希望它能帮助某人。

public class MyBottomsheetBehaviour extends BottomSheetBehavior {
    int lastY = 0;
    MyBottomsheetBehaviour() {
        super();
    }
    @Keep
    public MyBottomsheetBehaviour(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    @Override
    public boolean onInterceptTouchEvent(CoordinatorLayout parent, View view, MotionEvent event) {
        int dy = 0;
        boolean shouldWeConsumeIt = false;
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            lastY = (int) event.getY();
        } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) {
            lastY = 0;
        } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
            dy = (int) event.getY() - lastY;
        }
        Log.d("Swapnil", "onInterceptTouchEvent() event Y=" + event.getY() + " x=" + event.getX() + getActionType(event.getActionMasked()) + view.getClass().getSimpleName() + "dy=" + dy);
        if (view instanceof FrameLayout) {
            View child = ((ViewGroup) ((FrameLayout) view).getChildAt(0)).getChildAt(0);
            LinearLayoutManager manager = (LinearLayoutManager) ((RecyclerView) child).getLayoutManager();
            if (manager.findFirstCompletelyVisibleItemPosition() == 0 && dy > 0) {
                shouldWeConsumeIt = true;
                int parentHeight = view.getHeight();
                ViewCompat.offsetTopAndBottom(view, dy);
            } else if (manager.findFirstCompletelyVisibleItemPosition() == 0) {
                int height = ((View) view.getParent()).getHeight();
                int top = view.getTop();
                if ((event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) && top < (height >> 2)) {
                    view.setTop(0);
                    setState(BottomSheetBehavior.STATE_EXPANDED);
                } else if ((event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP)) {
                    setState(BottomSheetBehavior.STATE_COLLAPSED);
                }
            }
        }
        if (event.getAction() == MotionEvent.ACTION_MOVE) {
            lastY = (int) event.getY();
        }
        if (!shouldWeConsumeIt)
            return super.onInterceptTouchEvent(parent, view, event);
        return true;
    }
    @Override
    public boolean onTouchEvent(CoordinatorLayout parent, View child, MotionEvent event) {
        return super.onTouchEvent(parent, child, event);
    }
    private String getActionType(int eventType) {
        StringBuilder builder = new StringBuilder();
        if (eventType == MotionEvent.ACTION_DOWN)
            builder.append(" DOWN");
        else if ((eventType & MotionEvent.ACTION_UP) == MotionEvent.ACTION_UP)
            builder.append(" UP");
        else if ((eventType & MotionEvent.ACTION_CANCEL) == MotionEvent.ACTION_CANCEL)
            builder.append(" CANCEL");
        else if ((eventType & MotionEvent.ACTION_MOVE) == MotionEvent.ACTION_MOVE)
            builder.append(" MOVE");
        return builder.toString();
    }
}

相关内容

最新更新