tôi muốn khi kết thúc, nút bên phải sẽ thay đổi màu sắc, khi đạt đến bắt đầu, nút bên trái sẽ thay đổi màu sắc, vì vậy, tôi muốn hỏi cách phát hiện HorizontalScrollView đã kết thúc.Làm thế nào để phát hiện HorizontalScrollView đã đạt đến kết thúc
6
A
Trả lời
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
nơi để kích hoạt sự kiện này - bất kỳ người nghe nào cho nó? – NarendraJi
liên kết này sẽ giúp bạn: [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 –
[bài này có thể giúp bạn] (http: //stackoverflow.com/a/3952629/593709) –
maxScrollX = horizontalScrollView.getChildAt (0) \t \t .getMeasured Width() - horizontalScrollView.getMeasuredWidth(); nếu (horizontalScrollView.getScrollX() == 0) { \t \t \t \t \t lImageView.setImageResource (R.drawable.left_green); \t \t \t \t} else { \t \t \t \t \t lImageView.setImageResource (R.drawable.left); \t \t \t \t} \t \t \t \t if (horizontalScrollView.getScrollX() == maxScrollX) { \t \t \t \t \t rImageView.setImageResource (R.drawable.right_green); \t \t \t \t} else { \t \t \t \t \t rImageView.setImageResource (R.drawable.right); \t \t \t \t} – jack