水平Recyclerview覆盖滚动下一个View Pager片段

时间:2017-02-09 10:11:49

标签: android android-fragments android-viewpager android-recyclerview

我有一个包含3个片段的View寻呼机(带有FragmentPagerAdapter),其中一个片段有一个水平的Recyclerview作为其一部分。当我将视图寻呼机从一个片段(包含水平回收视图)滚动到另一个片段时,最后一个可见的recyclerview项目的剩余部分将在滚动时覆盖下一个片段。

MainAcitivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    tabLayout = (TabLayout) findViewById(R.id.tabs);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    pager = (ViewPager) findViewById(R.id.pager);
    fragment0 = new Fragment0();
    fragment1 = new Fragment1();
    fragment2 = new Fragment2();

    PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager());
    adapter.addFragment(fragment0, "A");
    adapter.addFragment(fragment1, "B");
    adapter.addFragment(fragment2, "C");
    pager.setAdapter(adapter);
    pager.setCurrentItem(0);

    tabLayout.setupWithViewPager(pager);
    tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.transparent));

    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
                pager.setCurrentItem(tabLayout.getSelectedTabPosition());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    });

}

PagerAdapter

public class PagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();

public PagerAdapter (FragmentManager manager) {
    super(manager);
}

@Override
public Fragment getItem(int position) {
    return mFragmentList.get(position);
}

@Override
public int getCount() {
    return mFragmentList.size();
}

public void addFragment(Fragment fragment, String title) {
    mFragmentList.add(fragment);
    mFragmentTitleList.add(title);
}

@Override
public CharSequence getPageTitle(int position) {
    return mFragmentTitleList.get(position);
}

}

并且Recycler视图是一个包含自定义视图的简单水平回收视图

请帮帮我.....

1 个答案:

答案 0 :(得分:0)

更改recyclerview的(我的意思是您的recyclerview的内容)宽度