如何在fragment里面嵌套viewpager?

public class One extends Fragment {
        
        private List list = new ArrayList();

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                        Bundle savedInstanceState) {
                View view = inflater.inflate(R.layout.one, null);
                return view;
        }
        
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
                super.onActivityCreated(savedInstanceState);
                ViewPager vp = (ViewPager) getView().findViewById(R.id.one_vp);
                
                list.add(new FragOne());//子fragment
                list.add(new FragTwo());//子fragment
                
                VpAdapter adapter = new VpAdapter(getChildFragmentManager(), list);
                vp.setAdapter(adapter);
        }
}

 

 

如此实现

转载于:https://www.cnblogs.com/Ringer/p/4077558.html

你可能感兴趣的:(如何在fragment里面嵌套viewpager?)