向 Android TouchListView 添加页脚

发布于 2024-11-24 08:03:15 字数 489 浏览 1 评论 0原文

您好,我正在使用这里的 TouchListView 控件: https://github.com/commonsguy/cwac-touchlist< /a> 我添加了一些按钮来添加到页脚中的列表:

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

一切似乎都工作正常,直到我拖动列表中的一项,此时页脚折叠(我认为是一个列表项的高度)模糊我添加的按钮。

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

Hi I'm using the TouchListView control from here: https://github.com/commonsguy/cwac-touchlist
and I've added some buttons to add to the list in the footer:

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

It all seems to be working fine until I drag an item in the list, at which point the footer collapses (to the height of one list item I think) obscuring the buttons I have added.

Can anyone suggest a fix/workaround for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开半夏魅人心 2024-12-01 08:03:15

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

问题出在 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 项目以包含此内容。

I actually worked this out shortly after asking it (always the way...)

The issue is in the doExpansion() and unExpandViews() methods which were modifying every item in the list including the footer. To fix it I created a method to check whether we are dealing with a draggable item or the footer:

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

And then modified the methods mentioned as follows:

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);
        }
    }
}

Would be worth updating the github project to include this I think.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文