4242import android .widget .ListAdapter ;
4343import android .widget .Scroller ;
4444
45- public class HorizontialListView extends AdapterView <ListAdapter > {
45+ public class HorizontalListView extends AdapterView <ListAdapter > {
4646
4747 public boolean mAlwaysOverrideTouch = true ;
4848 protected ListAdapter mAdapter ;
@@ -60,7 +60,7 @@ public class HorizontialListView extends AdapterView<ListAdapter> {
6060 private boolean mDataChanged = false ;
6161
6262
63- public HorizontialListView (Context context , AttributeSet attrs ) {
63+ public HorizontalListView (Context context , AttributeSet attrs ) {
6464 super (context , attrs );
6565 initView ();
6666 }
@@ -90,7 +90,7 @@ public void setOnItemClickListener(AdapterView.OnItemClickListener listener){
9090
9191 @ Override
9292 public void onChanged () {
93- synchronized (HorizontialListView .this ){
93+ synchronized (HorizontalListView .this ){
9494 mDataChanged = true ;
9595 }
9696 invalidate ();
@@ -170,11 +170,11 @@ protected synchronized void onLayout(boolean changed, int left, int top, int rig
170170 mNextX = scrollx ;
171171 }
172172
173- if (mNextX < 0 ){
173+ if (mNextX <= 0 ){
174174 mNextX = 0 ;
175175 mScroller .forceFinished (true );
176176 }
177- if (mNextX > mMaxX ) {
177+ if (mNextX >= mMaxX ) {
178178 mNextX = mMaxX ;
179179 mScroller .forceFinished (true );
180180 }
@@ -223,9 +223,13 @@ private void fillListRight(int rightEdge, final int dx) {
223223 addAndMeasureChild (child , -1 );
224224 rightEdge += child .getMeasuredWidth ();
225225
226- if (mRightViewIndex == mAdapter .getCount ()-1 ){
226+ if (mRightViewIndex == mAdapter .getCount ()-1 ) {
227227 mMaxX = mCurrentX + rightEdge - getWidth ();
228228 }
229+
230+ if (mMaxX < 0 ) {
231+ mMaxX = 0 ;
232+ }
229233 mRightViewIndex ++;
230234 }
231235
@@ -287,7 +291,7 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
287291
288292 protected boolean onFling (MotionEvent e1 , MotionEvent e2 , float velocityX ,
289293 float velocityY ) {
290- synchronized (HorizontialListView .this ){
294+ synchronized (HorizontalListView .this ){
291295 mScroller .fling (mNextX , 0 , (int )-velocityX , 0 , 0 , mMaxX , 0 , 0 );
292296 }
293297 requestLayout ();
@@ -304,20 +308,20 @@ protected boolean onDown(MotionEvent e) {
304308
305309 @ Override
306310 public boolean onDown (MotionEvent e ) {
307- return HorizontialListView .this .onDown (e );
311+ return HorizontalListView .this .onDown (e );
308312 }
309313
310314 @ Override
311315 public boolean onFling (MotionEvent e1 , MotionEvent e2 , float velocityX ,
312316 float velocityY ) {
313- return HorizontialListView .this .onFling (e1 , e2 , velocityX , velocityY );
317+ return HorizontalListView .this .onFling (e1 , e2 , velocityX , velocityY );
314318 }
315319
316320 @ Override
317321 public boolean onScroll (MotionEvent e1 , MotionEvent e2 ,
318322 float distanceX , float distanceY ) {
319323
320- synchronized (HorizontialListView .this ){
324+ synchronized (HorizontalListView .this ){
321325 mNextX += (int )distanceX ;
322326 }
323327 requestLayout ();
@@ -337,10 +341,10 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
337341 viewRect .set (left , top , right , bottom );
338342 if (viewRect .contains ((int )e .getX (), (int )e .getY ())){
339343 if (mOnItemClicked != null ){
340- mOnItemClicked .onItemClick (HorizontialListView .this , child , mLeftViewIndex + 1 + i , mAdapter .getItemId ( mLeftViewIndex + 1 + i ));
344+ mOnItemClicked .onItemClick (HorizontalListView .this , child , mLeftViewIndex + 1 + i , mAdapter .getItemId ( mLeftViewIndex + 1 + i ));
341345 }
342346 if (mOnItemSelected != null ){
343- mOnItemSelected .onItemSelected (HorizontialListView .this , child , mLeftViewIndex + 1 + i , mAdapter .getItemId ( mLeftViewIndex + 1 + i ));
347+ mOnItemSelected .onItemSelected (HorizontalListView .this , child , mLeftViewIndex + 1 + i , mAdapter .getItemId ( mLeftViewIndex + 1 + i ));
344348 }
345349 break ;
346350 }
0 commit comments