2012-03-07 46 views
6

我想要達到結束時,右按鈕將更改顏色,當到達開始時,左按鈕將更改顏色,所以,我想問如何檢測Horizo​​ntalScrollView已結束。如何檢測到Horizo​​ntalScrollView已到達結尾

+1

這個鏈接將幫助您: [http://stackoverflow.com/questions/2089552/android-how-to-detect-when-a-scroll-has-ended][1] [1]:http://stackoverflow.com/questions/2089552/android-how-to-detect-when-a-scroll-has-ended – 2012-03-07 08:28:21

+0

[此帖可能會幫助你(HTTP: //stackoverflow.com/a/3952629/593709) – 2012-03-07 08:29:07

+0

maxScrollX = horizo​​ntalScrollView.getChildAt(0) \t \t .getMeasured寬度() - horizo​​ntalScrollView.getMeasuredWidth(); 如果(horizo​​ntalScrollView.getScrollX()== 0){ \t \t \t \t \t lImageView.setImageResource(R.drawable.left_green); \t \t \t \t}否則{ \t \t \t \t \t lImageView.setImageResource(R.drawable.left); \t \t \t \t} \t \t \t \t如果(horizo​​ntalScrollView.getScrollX()== maxScrollX){ \t \t \t \t \t rImageView.setImageResource(R.drawable.right_green); \t \t \t \t}否則{ \t \t \t \t \t rImageView.setImageResource(R.drawable.right); \t \t \t \t} – jack 2012-03-08 03:36:55

回答

12
maxScrollX = horizontalScrollView.getChildAt(0).getMeasuredWidth()-horizontalScrollView.getMeasuredWidth(); 
    if (horizontalScrollView.getScrollX() == 0) { 
     lImageView.setImageResource(R.drawable.left_green); 
    } else { 
     lImageView.setImageResource(R.drawable.left); 
    } 

    if (horizontalScrollView.getScrollX() == maxScrollX) { 
     rImageView.setImageResource(R.drawable.right_green); 
    } else { 
     rImageView.setImageResource(R.drawable.right); 
    } 
+2

在哪裏觸發此事件 - 任何偵聽器? – NarendraJi 2015-10-24 11:52:12

相關問題