我有ViewPagerwitch在第一页上显示一些图像,但在第二页上我想在listview中显示一些图像,混淆如何在布局中进行单独的页面设置。 以下是添加页面的ViewPager方法
// Instantiate a ViewPager and a PagerAdapter.
mPager = (ViewPager) findViewById(R.id.pager);
mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
invalidateOptionsMenu();
}
});
这里是适配器
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return ScreenSlidePageFragment.create(position);
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
屏幕滑块ViewPager类
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPageNumber = getArguments().getInt(ARG_PAGE);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout containing a title and body text.
ViewGroup rootView = (ViewGroup) inflater
.inflate(R.layout.fragment_screen_slide_page, container, false);
// Set the title view to show the page number.
((TextView) rootView.findViewById(android.R.id.text1)).setText(
getString(R.string.title_template_step, mPageNumber + 1));
return rootView;
}
答案 0 :(得分:1)
您可以在ScreenSlidePagerAdapter更改getItem。在ScreenSlideSecondPageFragment中,您为第二页扩充布局。
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return ScreenSlidePageFragment.create(position);
case 1:
return ScreenSlideSecondPageFragment.create(position);
default:
return null;
}
}