栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

一起滚动ListView

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

一起滚动ListView

我创建了一个粗糙的类,基本上可以完成我想做的事情。它不是
足够聪明来处理,如果第二个名单是比第一或者更长的
方向变化,但它的好足以让这个概念了。

进行设置:

list1.setonScrollListener(new SyncedScrollListener(list2));list2.setonScrollListener(new SyncedScrollListener(list1));

SyncedScrollListener.java

package com.xorbix.util;import android.view.View;import android.widget.AbsListView;import android.widget.AbsListView.OnScrollListener;public class SyncedScrollListener implements OnScrollListener{    int offset;    int oldVisibleItem = -1;    int currentHeight;    int prevHeight;    private View mSyncedView;    public SyncedScrollListener(View syncedView){        if(syncedView == null){ throw new IllegalArgumentException("syncedView is null");        }        mSyncedView = syncedView;    }    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {        int[] location = new int[2];        if(visibleItemCount == 0){ return;        }        if(oldVisibleItem != firstVisibleItem){ if(oldVisibleItem < firstVisibleItem){     prevHeight = currentHeight;     currentHeight = view.getChildAt(0).getHeight();     offset += prevHeight; }else{     currentHeight = view.getChildAt(0).getHeight();     View prevView;     if((prevView = view.getChildAt(firstVisibleItem - 1)) != null){         prevHeight = prevView.getHeight();     }else{         prevHeight = 0;     }     offset -= currentHeight; } oldVisibleItem = firstVisibleItem;        }        view.getLocationOnScreen(location);        int listContainerPosition = location[1];        view.getChildAt(0).getLocationOnScreen(location);        int currentLocation = location[1];        int blah = listContainerPosition - currentLocation + offset;        mSyncedView.scrollTo(0, blah);    }    public void onScrollStateChanged(AbsListView view, int scrollState) {        // TODO Auto-generated method stub    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/516582.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号