Android - ScrollView添加提示Arrow(箭头)
来源:互联网 发布:怎么推广淘宝优惠券 编辑:程序博客网 时间:2024/05/22 03:27
ScrollView添加提示Arrow(箭头)
本文地址:http://blog.csdn.net/caroline_wendy
在ScrollView的滑动功能中,需要给用户提示,可以滑动,可以添加两个箭头。
定制ScrollView,创建监听器IScrollStateListener接口:
private IScrollStateListener scrollStateListener; public void setScrollStateListener(IScrollStateListener listener) { scrollStateListener = listener; } public interface IScrollStateListener { void onScrollMostLeft(); void onScrollFromMostLeft(); void onScrollMostRight(); void onScrollFromMostRight(); }
在监听滑动的时候,调用监听滑动事件(onScrollChanged):
@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
1 1
- Android - ScrollView添加提示Arrow(箭头)
- Raphael绘制箭头arrow
- Arrow Functions—箭头函数
- 用CSS实现箭头arrow
- ES6:箭头函数 Arrow Functions
- js箭头函数 => arrow
- 【ES6】之 Arrow Function箭头函数
- ES6箭头函数(arrow function)
- ES6箭头函数(Arrow Functions)
- css制作实心、空心arrow箭头
- ES6箭头函数(Arrow Functions)
- ES6箭头函数(Arrow Functions)
- 深入浅出ES6:箭头函数 Arrow Functions
- javaScript--arrow functions(箭头函数)解析
- ES6之箭头函数(Arrow Function)
- JavaScript Functional Programming:箭头函数 Arrow functions
- Android添加垂直滚动ScrollView
- Android添加垂直滚动ScrollView
- DataGridView 列大写、列只能输入数字
- Cadence SPB 16. 6 安装破解步骤
- DataGridView 添加行
- 国内网络用户达4.39亿
- ORACLE中如何输入日期(时间格式)
- Android - ScrollView添加提示Arrow(箭头)
- 关于studio升级到1.0.0-rc4后出现的 “Gradle DSL method not found: 'runProguard()'...”的问题解决方法
- [LeetCode] Pascal's Triangle II
- 括号配对问题
- Hibernate中CreateSQLQuery的executeUpdate(sql)方法的返回值
- Eclipse皮肤
- 删除Windows 7系统保留分区100MB
- 从谷歌搜索更多
- Struts2之struts2自带插件实现异步调用