ViewPager放在Fragment里面,改了改,沒報錯可以加載到虛擬機上,但是在虛擬機上運行后卻顯示停止運行!//這是源碼,沒發(fā)現(xiàn)有錯誤呀!
public?class?FirstFragment?extends?Fragment{
????private?ViewPager?mViewPager;
????private?int[]?mImagIds?=?new?int[]{R.mipmap.viewpager_1,R.mipmap.viewpager_2,R.mipmap.viewpager_3};
????private?List<View>?mImages?=?new?ArrayList<View>();
????public?View?onCreateView(LayoutInflater?inflater,?ViewGroup?container,Bundle?savedInstanceState){
????????View?view?=?inflater.inflate(R.layout.first_fragment,container,false);
????????mViewPager?=?(ViewPager)?view.findViewById(R.id.viewpager);
????????mViewPager.setAdapter(new?PagerAdapter()?{
????????????@Override
????????????public?Object?instantiateItem(ViewGroup?container,?int?position)?{
????????????????ImageView?imageview?=?new?ImageView(getActivity());
????????????????imageview.setImageResource(mImagIds[position]);
????????????????imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
????????????????container.addView(imageview);
????????????????return?imageview;
????????????}
????????????@Override
????????????public?void?destroyItem(ViewGroup?container,?int?position,?Object?object)?{
????????????????container.removeView(mImages.get(position));
????????????}
????????????@Override
????????????public?int?getCount()?{
????????????????return?mImagIds.length;
????????????}
????????????@Override
????????????public?boolean?isViewFromObject(View?view,?Object?object)?{
????????????????return?view?==?object;
????????????}
????????});
????????return?view;
????}
}
- 1 回答
- 0 關注
- 1331 瀏覽
添加回答
舉報
0/150
提交
取消