一:利用ViewPager实现Tab切换效果
1.首先新建几个要切换的xml布局文件,然后在主布局中间添加<android.support.v4.view.ViewPager>布局,用于显示我们写好的xml布局。
2.在主方法中,定添加代码如下:LayoutInflater mInflater = LayoutInflater.from(this);View tab01 = mInflater.inflate(R.layout.tab01, null);mViews.add(tab01);其中的mView代表我们list数据源。
3.实现PagerAdapter()适配器,注意要重写其中的destroyItem方法,在里面实现container.removeView(mViews.get(position)); 在public Object instantiateItem(ViewGroup container, int position)方法中获取当前显示的view,并将其添加到ViewGroup中