ViewPager 使用
太久没有接触android 今天再次重回android 一开始就来看看 Android 新功能 ViewPager
其主要功能 类似翻页效果,如微信,淘宝等首次使用都会出现的欢迎界面,一页一页的翻
ViewPage
我使用ViewPage 来做首页导航页面间的滑动
main_activity.xml
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
MainActivity.class
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ViewControl.getNavigationBar(this); } @Override protected void onRestart() { // TODO Auto-generated method stub super.onRestart(); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
ViewControl.class(界面中间代理层)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
NavigationBar.class (导航栏页面)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
MyPagerAdapte.class(ViewPage 的适配器)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public class MyPagerAdapter extends PagerAdapter { public List<View> mListViews; private Activity activity; private static String TAG = "MyPagerAdapter"; public MyPagerAdapter(List<View> mListViews,Activity activity) { this.mListViews = mListViews; this.activity = activity; } public void getViewClickListener(List<View> listview) { View v1 = listview.get(0); } @Override public void destroyItem(View arg0, int arg1, Object arg2) { ((ViewPager) arg0).removeView(mListViews.get(arg1)); } @Override public void finishUpdate(View arg0) { } @Override public int getCount() { return mListViews.size(); } @Override public Object instantiateItem(View arg0, int arg1) { ((ViewPager) arg0).addView(mListViews.get(arg1), 0); } return mListViews.get(arg1); } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == (arg1); } @Override public void restoreState(Parcelable arg0, ClassLoader arg1) { } @Override public Parcelable saveState() { return null; } @Override public void startUpdate(View arg0) { } }