ViewPager放在Fragment里面,改了改,没报错可以加载到虚拟机上,但是在虚拟机上运行后却显示停止运行!
//这是源码,没发现有错误呀!
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; } }
_遥不可及_
相关分类