首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

相仿iPhone的弹性ListView滚动

2012-08-31 
类似iPhone的弹性ListView滚动从2.3开始,android开始支持listview的overscroll, 应该很方便可以做出类似iP

类似iPhone的弹性ListView滚动
从2.3开始,android开始支持listview的overscroll, 应该很方便可以做出类似iPhone的弹性滚动,及越过list顶端或者底端,然后弹性滚回。昨天google了半天的例子,一个没找到,今天又试了试,发现用很简单的方式就可以实现这个效果。大致如下:
继承ListView
  private int delY;
  private boolean action_up;
在 onTouchEvent(){
           ...
          case MotionEvent.ACTION_MOVE:
            delY = (int) (preY - y);
            preY = y;
            break;
          case MotionEvent.ACTION_UP:
             action_up = true;
            break;
}

然后在2.3新增的onOverScrolled方法中做如下实现

protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX,   boolean clampedY) {    this.scrollBy(0, delY / 2);    if (action_up) {      this.scrollTo(0, 0);  }}


类似iPhone弹性效果的BounceListView
http://archive.cnblogs.com/a/2181042/


附送:
用字符串显示图片
做项目过程中遇到一个问题,从数据库里读取图片名称,然后调用图片。直接用R.drawable.?无法调用。查了好多地方最后找到了个方法,分享给大家,希望有帮助。
主要由两种方法,个人建议第二种。
1. 不把图片放在res/drawable下,而是存放在src某个package中(如:com.drawable.resource),这种情况下的调用方法为:
String path = "com/drawable/resource/image.png";
InputStream is = getClassLoader().getResourceAsStream(path);
Drawable.createFromStream(is, "src");

2. 如果还是希望直接使用res/drawable中的图片,就需要通过下面的方法了:
假设创建工程的时候,填写的package名字为:com.test.image
int resID = getResources().getIdentifier("goto_radar", "drawable", "com.test.image");
Drawable image = getResources().getDrawable(resID); 1 楼 libo19881179 2011-11-07   谢谢 以后会用得到的 以后2.3普及了会用的

热点排行