1

I'm adapting the QuickReturnListView from LarsWerkman to my application but it takes too long to scroll the list. My application shows rows with thumnails but all are the same size.

public void computeScrollY() {
    mHeight = 0;
    mItemCount = getAdapter().getCount();   
    mItemOffsetY.clear();

    for (int i=0;i<mItemCount;++i)
    {
        View view = getAdapter().getView(i, null, this);
        view.measure(
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            mItemOffsetY.add(i,  mHeight);
            mHeight += view.getMeasuredHeight();
    }
    scrollIsComputed = true;
 }

One thing I've thought to make this compute faster is not to called for every item to the getView because all my rows has the same size, but if I use the same view.getMeasuredHeight() for all the items the effect of the QuickReturnListView gets faulty. Can someone help me to improve this calculation? Thanks

4

1 回答 1

1

如果您的代码是这样工作的,并且您的底线大小相同,则可以使用以下代码更快地执行:

public void computeScrollY() {
    mHeight = 0;
    mItemCount = getAdapter().getCount();   
    mItemOffsetY.clear();

    if(mItemCount>0) {
        View view = getAdapter().getView(0, null, this);
        view.measure(
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        int h = view.getMeasuredHeight();
        for(int i=0; i<mItemCount;i++) {
            mItemOffsetY.add(i,  mHeight);
            mHeight += h;
        }
    }
    scrollIsComputed = true;
 }

您应该知道框 mItemOffset 0 处的元素在您的代码中始终为 0 吗?

您还应该知道,使用此代码您将知道所有元素的高度(甚至那些未显示的元素)而不考虑列数?

而且,调用getView 不是很干净,手动重新创建所有需要的实例,使View 这一切只是为了计算高度。

我希望能帮助你

于 2013-05-30T18:46:52.990 回答