20180530_Nested ScrollView의 충돌 해결 방안

2830 단어 android
20180530_Nested ScrollView의 충돌 해결 방안
제 해결 방안은 포기ViewPager, 개용RecyclerView+PagerSnapHelper입니다. 효과는 똑같습니다.
부분 참조 코드
        tl_tabs = (TabLayout) findViewById(R.id.tl_tabs);
        tl_tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                rv_pages.smoothScrollToPosition(tab.getPosition()); //   RecyclerView
            }
            // 
        });

        rv_pages = (RecyclerView) findViewById(R.id.rv_pages);
        final LinearLayoutManager llm = new LinearLayoutManager(this);
        llm.setOrientation(LinearLayoutManager.HORIZONTAL);
        rv_pages.setLayoutManager(llm);

        adapter = new PagerAdapter();
        rv_pages.setAdapter(adapter);
        rv_pages.addOnScrollListener(new RecyclerView.OnScrollListener() {
            private int mPreviousScrollState;
            private int mScrollState;
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);

                switch (newState) {
                    case RecyclerView.SCROLL_STATE_IDLE:
                        int position = llm.findFirstVisibleItemPosition();
                        TabLayout.Tab tab = tl_tabs.getTabAt(position);
                        if (tab != null) {
                            tab.select(); //   TabLayout
                        }
                        break;
                }
            }
            // 
        });

        new PagerSnapHelper().attachToRecyclerView(rv_pages); //   PagerSnapHelper   ViewPager      

좋은 웹페이지 즐겨찾기