Android implements left-right sliding Interface
The first thing to do is to slide the interface and multiple views are needed for switching. In fact, you can use an ArrayList PageViews to save the view information, and then switch
LayoutInflater inflater = getLayoutInflater();pageViews = new ArrayList
();pageViews.add(inflater.inflate(R.layout.item01, null));pageViews.add(inflater.inflate(R.layout.item02, null));pageViews.add(inflater.inflate(R.layout.item03, null));
Define the xml file for each item01, item02, and item03
What I wrote above is a relatively simple imageview for an item,
Here we have to say that a class GuidPageChangeListener must be defined to inherit the OnPageChangeListener interface to implement switching between views.
public void onPageSelected(int arg0) {// TODO Auto-generated method stubfor (int i = 0; i < imageViews.length; i++) {imageViews[arg0].setBackgroundResource(R.drawable.page_indicator_focused);if (arg0 != i) {imageViews[i].setBackgroundResource(R.drawable.page_indicator);}}}An adapter PagerAdapter class is also needed here. We need to write a class of our own to inherit it.
Class GuidPageAdapter extends PagerAdapter
The main reference method is as follows:
class GuidPageAdapter extends PagerAdapter {@Overridepublic int getCount() {// TODO Auto-generated method stubreturn pageViews.size();}@Overridepublic boolean isViewFromObject(View arg0, Object arg1) {// TODO Auto-generated method stubreturn arg0 == arg1;}@Overridepublic void destroyItem(View arg0, int arg1, Object arg2) {// TODO Auto-generated method stub((ViewPager) arg0).removeView(pageViews.get(arg1));}@Overridepublic Object instantiateItem(View arg0, int arg1) {// TODO Auto-generated method stub((ViewPager) arg0).addView(pageViews.get(arg1));return pageViews.get(arg1);}}
In this way, you can implement a simple switching between the left and right sides of the view. During this switching, the full screen is switched.
Reprinted please indicate the source
Http://blog.csdn.net/pishum/article/details/38024331