PinnedHeader谷歌,加上GridView的? [英] PinnedHeader Google plus GridView?

查看:153
本文介绍了PinnedHeader谷歌,加上GridView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌加(谷歌+)的应用程序对亮点类别一个很好的观看图像。

Google plus (google+) app has a nice viewing of images on the "highlights" category.

有关每一节在此屏幕上,他们提出一个包含可点击的文字和一个按钮,选择所有的照片本节的标题。每个区段它们也显示在一个网格状的方式的照片。

For each section on this screen, they made a header that contains a clickable text and a button to select all photos of this section. for each section they also show the photos in a grid-like manner.

下面是它的样子:

下面是另一个更多更新的形象:<一href="https://lh6.ggpht.com/2ocrzuKfmJLr0O2_Vmd5s4GAPa1a8sPbMWZBnq60rt2l7JDsylGjOOvAYAA-44g7Zg=h900-rw"相对=nofollow> 链接

Here's another more updated image: link .

由于某些原因,这里的图像显示共享按钮,而不是选择,但是这不是我想谈的问题。

For some reason, the images here show a sharing button instead of selections, but that's not the issue I wish to talk about.

我需要有一个类似浏览照片(包括头按钮/秒),同时也使头球顶始终可见(又名固定头,就像上的 项目 )。

I need to have a similar viewing of photos (including button/s on the headers) , but also make the top header always be visible (AKA "pinned header" , like on this project) .

其实,我甚至不关心它是否会被固定(虽然它可能是一个不错的功能)。

In fact, I don't even care if it will be pinned (though it could be a nice feature).

我发现只有2已固定的头GridView的库:

I've found only 2 libraries that have pinned header gridViews:

  1. StickyGridHeaders - 它看上去都不错。在API和code的设计是非常好的。不过,我已经用它在某些设备上播放,发现它与一个非常奇怪的异常崩溃。我已经报告了这件事 此处 ,但我看在其他问题上,我觉得这个项目不会得到很快解决。

  1. StickyGridHeaders - it seemed fine. the API and code design is very nice . However, i've played with it on some devices and found out it crashes with a very weird exception. i've reported about it here, but as I look at the other issues, I think this project won't get fixed anytime soon.

AStickyHeader - 这其中没有任何崩溃和错误,我可以找到,但它缺乏良好的code设计,并且它不是那么定制。报头不能被点击,它不能有一个按钮,像谷歌加。我已经试图加入,但由于某种原因,该按钮不会显示。我报道了我的发言就可以了 此处

是否有任何人谁试图处理这样的事情?

The question

Is there anyone who have tried to handle such a thing?

任何可用的库或修改,让我试着库有什么我写?

Any library available or a modification to the libraries I've tried that allow to have what I've written?

推荐答案

因为我无法找到任何其他的解决办法,我已经决定的基础上另外code I,使自己的解决方案(code已经取得了, 此处

since i can't find any other solution, i've decided to make my own solution (code based on another code i've made, here)

它是在一个ListView来代替,但它工作得很好。你刚才设置列表视图的适配器,你是好去。您可以设置标题完全看怎么样,也知道每个小区的样子。

it's used on a ListView instead, but it works quite well. you just set the adapter on the listView and you are good to go. you can set exactly how the headers look like and how each cell look like.

它的工作方式有2种类型的行:头,行和单元格,行。

it works by having 2 types of rows: header-rows and cells-rows .

这是不是最好的解决方案,因为它创建具有的ListView / GridView控件(或任何你使用)正确地把电池的额外的意见代替,但它工作得很好,它不会崩溃

it's not the best solution, since it creates extra views instead of having the ListView/GridView (or whatever you use) put the cells correctly, but it works fine and it doesn't crash

也没有项目点击(因为它是为ListView控件),但它不应该是很难增加对谁使用这个code。

it also doesn't have items clicking (since it's for listView), but it shouldn't be hard to add for whoever uses this code.

可悲的是它也没有一个固定的标题头,但也许它可能与 这个库(PinnedHeaderListView)

sadly it also doesn't have the header as a pinned header, but maybe it's possible to be used with this library (PinnedHeaderListView) .

这里的code:

public abstract class HeaderGridedListViewAdapter<SectionData, ItemType> extends BaseAdapter {
    private static final int TYPE_HEADER_ROW = 0;
    private static final int TYPE_CELLS_ROW = 1;
    private final int mNumColumns;
    private final List<Row<SectionData, ItemType>> mRows = new ArrayList<Row<SectionData, ItemType>>();
    private final int mCellsRowHeight;
    private final Context mContext;

    public HeaderGridedListViewAdapter(final Context context, final List<Section<SectionData, ItemType>> sections,
            final int numColumns, final int cellsRowHeight) {
        this.mContext = context;
        this.mNumColumns = numColumns;
        this.mCellsRowHeight = cellsRowHeight;
        for (final Section<SectionData, ItemType> section : sections) {
            // add header
            Row<SectionData, ItemType> row = new Row<SectionData, ItemType>();
            row.section = section;
            row.type = TYPE_HEADER_ROW;
            mRows.add(row);
            int startIndex = 0;
            // add section rows
            for (int cellsLeft = section.getItemsCount(); cellsLeft > 0;) {
                row = new Row<SectionData, ItemType>();
                row.section = section;
                row.startIndex = startIndex;
                row.type = TYPE_CELLS_ROW;
                cellsLeft -= Math.min(mNumColumns, cellsLeft);
                startIndex += mNumColumns;
                mRows.add(row);
            }
        }
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public int getItemViewType(final int position) {
        return getItem(position).type;
    }

    @Override
    public int getCount() {
        return mRows.size();
    }

    @Override
    public Row<SectionData, ItemType> getItem(final int position) {
        return mRows.get(position);
    }

    @Override
    public long getItemId(final int position) {
        return position;
    }

    @Override
    public View getView(final int position, final View convertView, final ViewGroup parent) {
        final Row<SectionData, ItemType> item = getItem(position);
        switch (item.type) {
        case TYPE_CELLS_ROW:
            LinearLayout rowLayout = (LinearLayout) convertView;
            if (rowLayout == null) {
                rowLayout = new LinearLayout(mContext);
                rowLayout.setOrientation(LinearLayout.HORIZONTAL);
                rowLayout.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, mCellsRowHeight));
                rowLayout.setWeightSum(mNumColumns);
            }
            final int childCount = rowLayout.getChildCount();
            // reuse previous views of the row if possible
            for (int i = 0; i < mNumColumns; ++i) {
                // reuse old views if possible
                final View cellConvertView = i < childCount ? rowLayout.getChildAt(i) : null;
                // fill cell with data
                final View cellView = getCellView(item.section, item.startIndex + i, cellConvertView, rowLayout);

                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) cellView.getLayoutParams();
                if (layoutParams == null) {
                    layoutParams = new LinearLayout.LayoutParams(0, mCellsRowHeight, 1);
                    cellView.setLayoutParams(layoutParams);
                } else {
                    final boolean needSetting = layoutParams.weight != 1 || layoutParams.width != 0
                            || layoutParams.height != mCellsRowHeight;
                    if (needSetting) {
                        layoutParams.width = 0;
                        layoutParams.height = mCellsRowHeight;
                        layoutParams.weight = 1;
                        cellView.setLayoutParams(layoutParams);
                    }
                }
                if (cellConvertView == null)
                    rowLayout.addView(cellView);
            }
            return rowLayout;
        case TYPE_HEADER_ROW:
            return getHeaderView(item.section, convertView, parent);
        }
        throw new UnsupportedOperationException("cannot create this type of row view");
    }

    @Override
    public boolean areAllItemsEnabled() {
        return false;
    }

    @Override
    public boolean isEnabled(final int position) {
        return false;
    }

    /** should handle getting a single header view */
    public abstract View getHeaderView(Section<SectionData, ItemType> section, View convertView, ViewGroup parent);

    /**
     * should handle getting a single cell view. <br/>
     * NOTE:read the parameters description carefully !
     * 
     * @param section
     *            the section that this cell belongs to
     * @param positionWithinSection
     *            the position within the section that we need to fill the data with. note that if it's larger than what
     *            the section can give you, it means we need an empty cell (same the the others, but shouldn't show
     *            anything, can be invisible if you wish)
     * @param convertView
     *            a recycled row cell. you must use it when it's not null, and fill it with data
     * @param parent
     *            the parent of the view. you should use it for inflating the view (but don't attach the view to the
     *            parent)
     */
    public abstract View getCellView(Section<SectionData, ItemType> section, int positionWithinSection,
            View convertView, ViewGroup parent);

    // ////////////////////////////////////
    // Section//
    // /////////
    public static class Section<SectionData, ItemType> {
        private final List<ItemType> mItems;
        private final SectionData mSectionData;

        public Section(final SectionData sectionData, final List<ItemType> items) {
            this.mSectionData = sectionData;
            this.mItems = items;
        }

        public SectionData getSectionData() {
            return mSectionData;
        }

        public int getItemsCount() {
            return mItems.size();
        }

        public ItemType getItem(final int posInSection) {
            return mItems.get(posInSection);
        }

        @Override
        public String toString() {
            return mSectionData;
        }
    }

    // ////////////////////////////////////
    // Row//
    // /////
    private static class Row<SectionData, ItemType> {
        int type, startIndex;
        Section<SectionData, ItemType> section;
    }
}

这篇关于PinnedHeader谷歌,加上GridView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆