android中的左右滑屏实现
2012-05-25 09:33:38 来源:WEB开发网核心提示:062}063064@Override065public void onPageScrolled(int arg0, float arg1, int arg2) {066Log.d("k", "onPageScrolled - " + arg0);067//从1到2滑动,在1滑动
062
}
063
064
@Override
065
public void onPageScrolled(int arg0, float arg1, int arg2) {
066
Log.d("k", "onPageScrolled - " + arg0);
067
//从1到2滑动,在1滑动前调用
068
}
069
070
@Override
071
public void onPageScrollStateChanged(int arg0) {
072
Log.d("k", "onPageScrollStateChanged - " + arg0);
073
//状态有三个0空闲,1是增在滑行中,2目标加载完毕
074
/**
075
* Indicates that the pager is in an idle, settled state. The current page
076
* is fully in view and no animation is in progress.
077
*/
078
//public static final int SCROLL_STATE_IDLE = 0;
079
/**
080
* Indicates that the pager is currently being dragged by the user.
081
*/
082
//public static final int SCROLL_STATE_DRAGGING = 1;
083
/**
084
* Indicates that the pager is in the process of settling to a final position.
085
*/
086
//public static final int SCROLL_STATE_SETTLING = 2;
087
088
}
089
});
090
091
}
092
093
private class MyPagerAdapter extends PagerAdapter{
094
095
@Override
096
public void destroyItem(View arg0, int arg1, Object arg2) {
097
Log.d("k", "destroyItem");
098
((ViewPager) arg0).removeView(mListViews.get(arg1));
099
}
100
101
@Override
102
public void finishUpdate(View arg0) {
103
Log.d("k", "finishUpdate");
104
}
105
106
@Override
107
public int getCount() {
108
Log.d("k", "getCount");
109
return mListViews.size();
110
}
111
112
@Override
113
public Object instantiateItem(View arg0, int arg1) {
114
Log.d("k", "instantiateItem");
115
((ViewPager) arg0).addView(mListViews.get(arg1),0);
116
return mListViews.get(arg1);
117
}
118
119
@Override
120
public boolean isViewFromObject(View arg0, Object arg1) {
121
Log.d("k", "isViewFromObject");
122
return arg0==(arg1);
123
}
124
125
@Override
126
public void restoreState(Parcelable arg0, ClassLoader arg1) {
127
Log.d("k", "restoreState");
128
}
129
130
@Override
131
public Parcelable saveState() {
132
Log.d("k", "saveState");
133
return null;
134
}
135
136
@Override
137
public void startUpdate(View arg0) {
138
Log.d("k", "startUpdate");
139
}
140
141
}
142
143
} 在实机上测试后,非常流畅,这也就是说官方版的左右滑屏控件已经实现
目前,关于viewpager的文章非常少,本文是通过阅读viewpager源代码分析出的写法
}
063
064
@Override
065
public void onPageScrolled(int arg0, float arg1, int arg2) {
066
Log.d("k", "onPageScrolled - " + arg0);
067
//从1到2滑动,在1滑动前调用
068
}
069
070
@Override
071
public void onPageScrollStateChanged(int arg0) {
072
Log.d("k", "onPageScrollStateChanged - " + arg0);
073
//状态有三个0空闲,1是增在滑行中,2目标加载完毕
074
/**
075
* Indicates that the pager is in an idle, settled state. The current page
076
* is fully in view and no animation is in progress.
077
*/
078
//public static final int SCROLL_STATE_IDLE = 0;
079
/**
080
* Indicates that the pager is currently being dragged by the user.
081
*/
082
//public static final int SCROLL_STATE_DRAGGING = 1;
083
/**
084
* Indicates that the pager is in the process of settling to a final position.
085
*/
086
//public static final int SCROLL_STATE_SETTLING = 2;
087
088
}
089
});
090
091
}
092
093
private class MyPagerAdapter extends PagerAdapter{
094
095
@Override
096
public void destroyItem(View arg0, int arg1, Object arg2) {
097
Log.d("k", "destroyItem");
098
((ViewPager) arg0).removeView(mListViews.get(arg1));
099
}
100
101
@Override
102
public void finishUpdate(View arg0) {
103
Log.d("k", "finishUpdate");
104
}
105
106
@Override
107
public int getCount() {
108
Log.d("k", "getCount");
109
return mListViews.size();
110
}
111
112
@Override
113
public Object instantiateItem(View arg0, int arg1) {
114
Log.d("k", "instantiateItem");
115
((ViewPager) arg0).addView(mListViews.get(arg1),0);
116
return mListViews.get(arg1);
117
}
118
119
@Override
120
public boolean isViewFromObject(View arg0, Object arg1) {
121
Log.d("k", "isViewFromObject");
122
return arg0==(arg1);
123
}
124
125
@Override
126
public void restoreState(Parcelable arg0, ClassLoader arg1) {
127
Log.d("k", "restoreState");
128
}
129
130
@Override
131
public Parcelable saveState() {
132
Log.d("k", "saveState");
133
return null;
134
}
135
136
@Override
137
public void startUpdate(View arg0) {
138
Log.d("k", "startUpdate");
139
}
140
141
}
142
143
} 在实机上测试后,非常流畅,这也就是说官方版的左右滑屏控件已经实现
目前,关于viewpager的文章非常少,本文是通过阅读viewpager源代码分析出的写法
更多精彩
赞助商链接