Android - ScrollView添加提示Arrow(箭头)
ScrollView添加提示Arrow(箭头)
本文地址:http://blog.csdn.net/caroline_wendy
在ScrollView的滑动功能中,需要给用户提示,可以滑动,可以添加两个箭头。
private IScrollStateListener scrollStateListener; public void setScrollStateListener(IScrollStateListener listener) { scrollStateListener = listener; } public interface IScrollStateListener { void onScrollMostLeft(); void onScrollFromMostLeft(); void onScrollMostRight(); void onScrollFromMostRight(); }
@Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); if (scrollStateListener != null) { if (l == 0) { scrollStateListener.onScrollMostLeft(); } else if (oldl == 0) { scrollStateListener.onScrollFromMostLeft(); } int mostRightL = this.getChildAt(0).getWidth()-getWidth(); if (l >= mostRightL) { scrollStateListener.onScrollMostRight(); } else if (oldl >= mostRightL && l < mostRightL) { scrollStateListener.onScrollFromMostRight(); } } }
final ImageView leftArrow = (ImageView)view.findViewById(R.id.doctor_gather_imageview_leftarrow); final ImageView rightArrow = (ImageView)view.findViewById(R.id.doctor_gather_imageview_rightarrow); AutoHorizontalScrollView scrollView = (AutoHorizontalScrollView)view.findViewById(R.id.doctor_gather_scrollview); scrollView.setScrollStateListener(new AutoHorizontalScrollView.IScrollStateListener() { @Override public void onScrollMostLeft() { Log.e(DEBUG + TAG, "滑动条最左面"); leftArrow.setVisibility(View.INVISIBLE); rightArrow.setVisibility(View.VISIBLE); } @Override public void onScrollFromMostLeft() { Log.e(DEBUG+TAG, "滑动条离开最左面"); leftArrow.setVisibility(View.VISIBLE); rightArrow.setVisibility(View.VISIBLE); } @Override public void onScrollMostRight() { Log.e(DEBUG+TAG, "滑动条最右面"); leftArrow.setVisibility(View.VISIBLE); rightArrow.setVisibility(View.INVISIBLE); } @Override public void onScrollFromMostRight() { Log.e(DEBUG+TAG, "滑动条离开最右面"); leftArrow.setVisibility(View.VISIBLE); rightArrow.setVisibility(View.VISIBLE); } });
参考:http://stackoverflow.com/questions/9062227/how-to-set-images-for-scrollview-instead-of-fading-edges
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。