2

嗨,我在这里使用 TouchListView 控件:https ://github.com/commonsguy/cwac-touchlist 并且我添加了一些按钮以添加到页脚的列表中:

    mFooter = getLayoutInflater().inflate(R.layout.edit_homepage_footer_layout, null);
    mListView = (TouchListView) findViewById(R.id.sectionList);
    mListView.addFooterView(mFooter);

在我拖动列表中的一个项目之前,这一切似乎都运行良好,此时页脚折叠(到我认为的一个列表项目的高度)遮盖了我添加的按钮。

任何人都可以为此建议修复/解决方法吗?

4

1 回答 1

2

我实际上是在询问后不久就解决了这个问题(总是这样......)

问题出在 doExpansion() 和 unExpandViews() 方法中,它们正在修改列表中的每个项目,包括页脚。为了解决这个问题,我创建了一个方法来检查我们是在处理可拖动项目还是页脚:

private boolean isDraggableItem(View view) {
    View dragger = view.findViewById(grabberId);
    return dragger != null;
}

然后将提到的方法修改如下:

private void unExpandViews(boolean deletion) {
    for (int i = 0; ; i++) {
        View v = getChildAt(i);
        if (v == null) {
            if (deletion) {
                // HACK force update of mItemCount
                int position = getFirstVisiblePosition();
                int y = getChildAt(0).getTop();
                setAdapter(getAdapter());
                setSelectionFromTop(position, y);
                // end hack
            }
            layoutChildren(); // force children to be recreated where needed
            v = getChildAt(i);
            if (v == null) {
                break;
            }
        }
        if (isDraggableItem(v)) { //check this view isn't the footer
            ViewGroup.LayoutParams params = v.getLayoutParams();
            params.height = mItemHeightNormal;
            v.setLayoutParams(params);
            v.setVisibility(View.VISIBLE);
        }
    }
}

private void doExpansion() {
    Log.d(logTag, "Doing expansion");
    int childnum = mDragPos - getFirstVisiblePosition();
    if (mDragPos > mFirstDragPos) {
        childnum++;
    }

    View first = getChildAt(mFirstDragPos - getFirstVisiblePosition());

    for (int i = 0; ; i++) {
        View vv = getChildAt(i);
        if (vv == null) {
            break;
        }
        int height = mItemHeightNormal;
        int visibility = View.VISIBLE;
        if (vv.equals(first)) {
            // processing the item that is being dragged
            if (mDragPos == mFirstDragPos) {
                // hovering over the original location
                visibility = View.INVISIBLE;
            } else {
                // not hovering over it
                height = 1;
            }
        } else if (i == childnum) {
            if (mDragPos < getCount() - 1) {
                height = mItemHeightExpanded;
            }
        }
        if (isDraggableItem(vv)) { //check this view isn't the footer
            ViewGroup.LayoutParams params = vv.getLayoutParams();
            params.height = height;
            vv.setLayoutParams(params);
            vv.setVisibility(visibility);
        }
    }
}

我认为值得更新 github 项目以包含此内容。

于 2011-07-15T16:15:38.860 回答