在Android中向多列GridView添加页脚视图?

发布于 2024-11-01 18:41:36 字数 121 浏览 1 评论 0原文

是否可以将页脚视图添加到 GridView(具有多列),其行为类似于 ListView 的页脚?那么这个页脚视图(例如分页视图)仅在用户滚动到 GridView 底部时出现,并且它具有整个屏幕的宽度,而不仅仅是 1 个网格元素?

Is it possible to add a footer View to a GridView (which has multiple columns) that behaves like a footer of a ListView? So this footer View (e.g. a pager view) appears only when the user scrolls to the bottom of the GridView, and it has the width of the whole screen, not only 1 grid element?

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

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

发布评论

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

评论(2

国粹 2024-11-08 18:41:36

不,抱歉,GridView 不提供此类功能。

您提到将其用于“寻呼机视图”。如果您的意思是“单击此处获取更多”条目,那么一旦到达当前网格数据的末尾,我就会延迟加载数据。我的 EndlessAdapter 可以处理这个问题,虽然我还没有尝试过 < code>GridView,它可能会起作用——至少,我认为它应该起作用。

No, sorry, GridView does not offer this sort of capability.

You mention using this for a "pager view". If, by that, you mean a "click here for more" entry, I'd just lazy-load the data once the end of the current grid data is reached. My EndlessAdapter handles that, and while I have not tried it with GridView, it may work -- leastways, I think it should.

記柔刀 2024-11-08 18:41:36

在 gridview 适配器中,您可以执行以下操作:

@Override
public int getCount() {
    return (footerView == null) ? super.getCount() : super.getCount() + 1;
}

public void setFooterView(View v) {
    footerView = v;
}

// create a new view item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
    if (footerView != null && position == getCount()-1) {
        return footerView;
    }
    ViewHolder holder;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        LayoutInflater lyinflater = LayoutInflater.from(mContext);
        View view = lyinflater.inflate(getLayoutItemId(), null);
        ...
        holder = new ViewHolder();
        ...
        convertView = view;
        view.setTag(holder);
    } else {
        holder = (ViewHolder)convertView.getTag();
    }
    ...
    return convertView;
}

编辑
抱歉,我没有阅读最后一部分

并且它具有整个屏幕的宽度

In the gridview adapter you can do this:

@Override
public int getCount() {
    return (footerView == null) ? super.getCount() : super.getCount() + 1;
}

public void setFooterView(View v) {
    footerView = v;
}

// create a new view item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
    if (footerView != null && position == getCount()-1) {
        return footerView;
    }
    ViewHolder holder;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        LayoutInflater lyinflater = LayoutInflater.from(mContext);
        View view = lyinflater.inflate(getLayoutItemId(), null);
        ...
        holder = new ViewHolder();
        ...
        convertView = view;
        view.setTag(holder);
    } else {
        holder = (ViewHolder)convertView.getTag();
    }
    ...
    return convertView;
}

EDIT
Sorry I did not read the last part

and it has the width of the whole screen

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