如何检测Horizo​​ntalScrollView已到达终点

时间:2012-03-07 08:20:26

标签: android horizontalscrollview

我希望当到达结束时,右键会改变颜色,当到达开头时,左键会改变颜色,所以,我想问一下如何检测Horizo​​ntalScrollView已经到了结尾。

1 个答案:

答案 0 :(得分: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); 
    }