如何在父视图变得可滚动之前停止绘制 GridView 项目?

发布于 2024-11-05 04:21:26 字数 1820 浏览 4 评论 0原文

我正在尝试使用 GridView 填充 ViewFlipper,但具有分页功能而不是滚动功能。 GridView 将填充单个“页面”(无需滚动的完整页面),并开始使用数据集的下一位填充 ViewFlipper 中的下一个视图。

我需要动态填充页面,因为屏幕尺寸会有所不同。这个 GridView 带有一个带有 getView() 重写的自定义适配器类,所以我认为最优雅的解决方案是在 GridView 中正常绘制视图,但这就是我遇到一些困惑的地方:

有两件事:

我如何告诉 getView() 函数将 GridView 项写入下一个 <代码>查看 ViewFlipper?由此看来,我如何知道屏幕何时填充到滚动条弹出之前(我不需要可滚动列表,这是使用 ViewFlipper 的全部要点)。

还是有我还没有找到的更好的解决方案?我在 API 演示中找不到示例,除了这个之外,在 stackoverflow 上几乎没有找到任何信息,但我仍然需要上述两个建议来使该解决方案发挥作用(除非有更好的东西): Android ViewFlipper 不翻转

GridView 适配器:

// custom adapter made for the GridView
public class ButtonAdapter extends BaseAdapter {
    private Context mContext;
    private List<Map<String, String>> mData;
    private int mLayout;

    public ButtonAdapter(Context c, int layout, List<Map<String, String>> list) {
        this.mContext = c;
        this.mData = list;
        this.mLayout=layout;
    }

    public int getCount() {
        return mData.size();
    }

    public Object getItem(int position) {
        return mData.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        Button btn = null;

        if(convertView==null) {
            convertView = inflater.inflate(this.mLayout, null);
        }

        btn = (Button)convertView.findViewById(R.id.grid_btn);
        if(btn != null) {
            //btn.setPadding(8,8,8,8);
            btn.setText(mData.get(position).get("label"));
            btn.setId(position);
        }

        return convertView;
    }
}

I'm trying to populate a ViewFlipper with a GridView, but with a paging capability rather than scrolling. The GridView will fill out a single "page" (one complete page without scrolling), and start filling out the next View in the ViewFlipper with the next bit of the data set.

I need to dynamically fill the pages, as the screen sizes will vary. This GridView sports a custom adapter class with a getView() override, so I was thinking the most elegant solution would be to draw the view as normal in the GridView, but this is where I run into some confusion:

Two things:

How can i tell the getView() function to write the GridView items to the next View in the ViewFlipper? And by that token, how can I know when the screen fills to just before the scroll bar pops up (I don't want scrollable lists, which was the whole point in using a ViewFlipper).

Or is there a better solution that i just haven't found yet? I couldn't find an example in the API demos and little info here on stackoverflow except this, which got me started, but I still need the above two suggestions to make this solution work (unless there's something better): Android ViewFlipper not flipping

The GridView adapter:

// custom adapter made for the GridView
public class ButtonAdapter extends BaseAdapter {
    private Context mContext;
    private List<Map<String, String>> mData;
    private int mLayout;

    public ButtonAdapter(Context c, int layout, List<Map<String, String>> list) {
        this.mContext = c;
        this.mData = list;
        this.mLayout=layout;
    }

    public int getCount() {
        return mData.size();
    }

    public Object getItem(int position) {
        return mData.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        Button btn = null;

        if(convertView==null) {
            convertView = inflater.inflate(this.mLayout, null);
        }

        btn = (Button)convertView.findViewById(R.id.grid_btn);
        if(btn != null) {
            //btn.setPadding(8,8,8,8);
            btn.setText(mData.get(position).get("label"));
            btn.setId(position);
        }

        return convertView;
    }
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文