android.support.v7.widget.StaggeredGridLayoutManager Java Examples

The following examples show how to use android.support.v7.widget.StaggeredGridLayoutManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DividerGridItemDecoration.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * 判断是否是最后一列
 */
private boolean isLastColumn(RecyclerView parent, int pos, int spanCount, int childCount) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0) {// 如果是最后一列,则不需要绘制右边
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0) {// 如果是最后一列,则不需要绘制右边
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount) {// 如果是最后一列,则不需要绘制右边
                return true;
            }
        }
    }
    return false;
}
 
Example #2
Source File: HomeActivity.java    From DS4Android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mData.add(R.mipmap.array_list);
    mData.add(R.mipmap.singel_linked);
    mData.add(R.mipmap.linked_list);
    mData.add(R.mipmap.stack);
    mData.add(R.mipmap.queue);
    mData.add(R.mipmap.bst);

    setContentView(R.layout.activity_home);

    mRecyclerView = findViewById(R.id.id_rv);
    mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
    mRecyclerView.setAdapter(new HomeRVAdapter(this, mData));
}
 
Example #3
Source File: SupportGridItemDecoration.java    From BookReader with Apache License 2.0 6 votes vote down vote up
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
                            int childCount) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
 
Example #4
Source File: DefaultItemDecoration.java    From SwipeRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent,
    @NonNull RecyclerView.State state) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof LinearLayoutManager) {
        int orientation = getOrientation(layoutManager);
        int position = parent.getChildLayoutPosition(view);
        int spanCount = getSpanCount(layoutManager);
        int childCount = layoutManager.getItemCount();

        if (orientation == RecyclerView.VERTICAL) {
            offsetVertical(outRect, position, spanCount, childCount);
        } else {
            offsetHorizontal(outRect, position, spanCount, childCount);
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        outRect.set(mWidth, mHeight, mWidth, mHeight); // |-|-
    }
}
 
Example #5
Source File: DividerGridItemDecoration.java    From ExRecyclerView with Apache License 2.0 6 votes vote down vote up
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
        int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        }
    }
    return false;
}
 
Example #6
Source File: EndlessRecyclerView.java    From materialup with Apache License 2.0 6 votes vote down vote up
/**
 * if layout manager do not have this method , will return 0
 *
 * @return
 */
public int findFirstVisibleItemPosition() {
    LayoutManager manager = getLayoutManager();

    int firstVisibleItems = 0;
    if (manager instanceof LinearLayoutManager) {
        firstVisibleItems = ((LinearLayoutManager) manager).findFirstVisibleItemPosition();
    } else if (manager instanceof GridLayoutManager) {
        firstVisibleItems = ((GridLayoutManager) manager).findFirstVisibleItemPosition();
    } else if (manager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager sg = ((StaggeredGridLayoutManager) manager);
        int[] items = new int[sg.getSpanCount()];
        items = ((StaggeredGridLayoutManager) manager).findFirstVisibleItemPositions(items);
        firstVisibleItems = items[0];
    }

    return firstVisibleItems;
}
 
Example #7
Source File: QuickReturnRecyclerView.java    From droidddle with Apache License 2.0 6 votes vote down vote up
/**
 * if layout manager do not have this method , will return 0
 *
 * @return
 */
public int findFirstVisibleItemPosition() {
    LayoutManager manager = getLayoutManager();

    int firstVisibleItems = 0;
    if (manager instanceof LinearLayoutManager) {
        firstVisibleItems = ((LinearLayoutManager) manager).findFirstVisibleItemPosition();
    } else if (manager instanceof GridLayoutManager) {
        firstVisibleItems = ((GridLayoutManager) manager).findFirstVisibleItemPosition();
    } else if (manager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager sg = ((StaggeredGridLayoutManager) manager);
        int[] items = new int[sg.getSpanCount()];
        items = ((StaggeredGridLayoutManager) manager).findFirstVisibleItemPositions(items);
        firstVisibleItems = items[0];
    }

    return firstVisibleItems;
}
 
Example #8
Source File: Utils.java    From MaterialViewPager with Apache License 2.0 6 votes vote down vote up
public static void scrollTo(Object scroll, float yOffset) {
    if (scroll instanceof RecyclerView) {
        //RecyclerView.scrollTo : UnsupportedOperationException
        //Moved to the RecyclerView.LayoutManager.scrollToPositionWithOffset
        //Have to be instanceOf RecyclerView.LayoutManager to work (so work with RecyclerView.GridLayoutManager)
        final RecyclerView.LayoutManager layoutManager = ((RecyclerView) scroll).getLayoutManager();
        if (layoutManager instanceof LinearLayoutManager) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
            linearLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            staggeredGridLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        }
    } else if (scroll instanceof NestedScrollView) {
        ((NestedScrollView) scroll).scrollTo(0, (int) yOffset);
    }
}
 
Example #9
Source File: DividerGridItemDecoration.java    From ImageSelector with Apache License 2.0 6 votes vote down vote up
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
                            int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
 
Example #10
Source File: StaggeredLayoutManagerInternalUtils.java    From RecyclerViewTools with Apache License 2.0 6 votes vote down vote up
static void setFullWidthLayoutParams(View parent, RecyclerView.ViewHolder holder) {

      // is recycler view (should be)
      if (!(parent instanceof RecyclerView)) {
         return;
      }
      RecyclerView rv = (RecyclerView) parent;

      // is grid layout manager, maybe is, maybe not
      if (!(rv.getLayoutManager() instanceof StaggeredGridLayoutManager)) {
         return;
      }

      StaggeredGridLayoutManager.LayoutParams lp;
      if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
         lp = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
         lp.setFullSpan(true);
      } else {
         lp = new StaggeredGridLayoutManager.LayoutParams(holder.itemView.getLayoutParams());
         lp.setFullSpan(true);
         holder.itemView.setLayoutParams(lp);
      }
   }
 
Example #11
Source File: DividerGridItemDecoration.java    From FimiX8-RE with MIT License 6 votes vote down vote up
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if (pos >= childCount - (childCount % spanCount)) {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        if (((StaggeredGridLayoutManager) layoutManager).getOrientation() == 1) {
            if (pos >= childCount - (childCount % spanCount)) {
                return true;
            }
        } else if ((pos + 1) % spanCount == 0) {
            return true;
        }
    }
    return false;
}
 
Example #12
Source File: HeaderAndFooterWrapperAdapter.java    From all-base-adapter with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
    int position = holder.getLayoutPosition();
    if (isHeaderViewPos(position) || isFooterViewPos(position)) {
        ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();

        if (lp != null
                && lp instanceof StaggeredGridLayoutManager.LayoutParams) {

            StaggeredGridLayoutManager.LayoutParams p =
                    (StaggeredGridLayoutManager.LayoutParams) lp;

            p.setFullSpan(true);
        }
        super.onViewAttachedToWindow(holder);
    } else {
        mInnerAdapter.onViewAttachedToWindow(holder);
    }
}
 
Example #13
Source File: RecyclerViewUtils.java    From PowerfulRecyclerView with Apache License 2.0 6 votes vote down vote up
/**
 * 设置加载更多的footer
 *
 * @param mRecycler
 * @param foot
 */
public void setFootView(RecyclerView mRecycler,View foot){
    RecyclerView.Adapter mAdapter = mRecycler.getAdapter();

    if(mAdapter == null || !(mAdapter instanceof PowerfulRecyclerAdapter)){
        return ;
    }

    PowerfulRecyclerAdapter realAdapter = (PowerfulRecyclerAdapter)mAdapter;
    if(realAdapter.hasFootView()){
        return;
    }

    RecyclerView.LayoutManager manager = mRecycler.getLayoutManager();

    int spanCount = 1;

    if(manager instanceof GridLayoutManager){
        spanCount = ((GridLayoutManager)manager).getSpanCount();
    }else if(manager instanceof StaggeredGridLayoutManager) {
        spanCount = ((StaggeredGridLayoutManager) manager).getSpanCount();
    }

    realAdapter.setFootView(foot, spanCount);
}
 
Example #14
Source File: PullableRecyclerView.java    From PullToRefresh with Apache License 2.0 6 votes vote down vote up
/**
 * 获取底部可见项的位置
 *
 * @return
 */
public int getLastVisibleItemPosition()
{
    LayoutManager lm = getLayoutManager();
    int lastVisibleItemPosition = 0;
    if (lm instanceof GridLayoutManager)
    {
        lastVisibleItemPosition = ((GridLayoutManager) lm).findLastVisibleItemPosition();
    } else if (lm instanceof LinearLayoutManager)
    {
        lastVisibleItemPosition = ((LinearLayoutManager) lm).findLastVisibleItemPosition();
    } else if (lm instanceof StaggeredGridLayoutManager)
    {
        int positions[] = new int[1];
        ((StaggeredGridLayoutManager) lm).findLastVisibleItemPositions(positions);
        lastVisibleItemPosition = positions[0];
    }
    return lastVisibleItemPosition;
}
 
Example #15
Source File: UDBaseRecyclerView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
/**
 * TODO 支持offset
 *
 * @param section
 * @param rowInSection
 * @param offset
 * @param animate
 * @return
 */
@Override
public UDBaseListOrRecyclerView scrollToItem(int section, int rowInSection, int offset, boolean animate) {
    LVRecyclerView recyclerView = getLVRecyclerView();
    if (recyclerView != null) {
        if (animate) {
            recyclerView.smoothScrollToPosition(getPositionBySectionAndRow(section, rowInSection));
        } else {
            if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
                ((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(getPositionBySectionAndRow(section, rowInSection), offset);
            } else if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
                ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(getPositionBySectionAndRow(section, rowInSection), offset);
            } else {
                recyclerView.scrollToPosition(getPositionBySectionAndRow(section, rowInSection));
            }
        }
    }
    return this;
}
 
Example #16
Source File: LoadMoreRecyclerView.java    From LoadMoreRecyclerView with Apache License 2.0 6 votes vote down vote up
/**
 * 获取第一条展示的位置
 *
 * @return
 */
private int getFirstVisiblePosition() {
    int position;
    if (getLayoutManager() instanceof LinearLayoutManager) {
        position = ((LinearLayoutManager) getLayoutManager()).findFirstVisibleItemPosition();
    } else if (getLayoutManager() instanceof GridLayoutManager) {
        position = ((GridLayoutManager) getLayoutManager()).findFirstVisibleItemPosition();
    } else if (getLayoutManager() instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) getLayoutManager();
        int[] lastPositions = layoutManager.findFirstVisibleItemPositions(new int[layoutManager.getSpanCount()]);
        position = getMinPositions(lastPositions);
    } else {
        position = 0;
    }
    return position;
}
 
Example #17
Source File: XRecyclerView.java    From ARecyclerView with MIT License 6 votes vote down vote up
private void setSpanLookUp(RecyclerView.LayoutManager layoutManager, final int spanCount) {
    if (layoutManager instanceof GridLayoutManager) {
        ((GridLayoutManager) layoutManager).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (adapter != null) {
                    return adapter.isHeaderOrFooter(position) ? spanCount : 1;
                }
                return GridLayoutManager.DEFAULT_SPAN_COUNT;
            }
        });
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        ((StaggeredGridLayoutManager) layoutManager).setSpanCount(spanCount);
    }

}
 
Example #18
Source File: DividerGridItemDecoration.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
/**
 * is position align top of recycler view
 * 从当前位置找起,只要找到一个跟自己的spanIndex一样的就说明不是第一行,或者已经查找过的spancount >= spanCount说明不是第一行
 *
 * @param parent
 * @param position
 * @param totalSpanCount
 * @return
 */
boolean isTop(RecyclerView parent, int position, int totalSpanCount) {
    if (parent.getLayoutManager() instanceof GridLayoutManager) {
        GridLayoutManager.SpanSizeLookup sizeLookup = ((GridLayoutManager) parent.getLayoutManager()).getSpanSizeLookup();
        if (sizeLookup != null) {
            int currentSpanIndex = sizeLookup.getSpanIndex(position, totalSpanCount);
            int lookupedSpanCount = 0;
            for (int i = position - 1; i >= 0; i--) {
                lookupedSpanCount = lookupedSpanCount + sizeLookup.getSpanSize(i);
                if (lookupedSpanCount >= totalSpanCount) {
                    return false;
                }
                if (sizeLookup.getSpanIndex(i, totalSpanCount) == currentSpanIndex) {
                    return false;
                }
            }
            return true;
        }
    } else if (parent.getLayoutManager() instanceof StaggeredGridLayoutManager) {
        return position < totalSpanCount;//staggered 的每一列一个span
    }
    return false;
}
 
Example #19
Source File: OnRecyclerViewScrollListener.java    From HeaderFooterRecyclerView with Apache License 2.0 6 votes vote down vote up
/**
 * 计算第一个元素的位置
 */
private int calculateFirstVisibleItemPos(RecyclerView.LayoutManager layoutManager, int firstVisibleItemPosition) {
    switch (mLayoutManagerType) {
        case LINEAR:
            mLastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            firstVisibleItemPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
            break;
        case GRID:
            mLastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            firstVisibleItemPosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
            break;
        case STAGGERED_GRID:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (mLastPositions == null) {
                mLastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            mLastPositions = staggeredGridLayoutManager.findLastVisibleItemPositions(mLastPositions);
            mLastVisibleItemPosition = findMax(mLastPositions);
            staggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions(mLastPositions);
            firstVisibleItemPosition = findMax(mLastPositions);
            break;
    }
    return firstVisibleItemPosition;
}
 
Example #20
Source File: HomeFragment.java    From MousePaint with MIT License 6 votes vote down vote up
@Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        // Layout Managers:
        final StaggeredGridLayoutManager layoutManager =
                new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);

        // Item Decorator:
//        recyclerView.addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.divider)));
//        recyclerView.setItemAnimator(new FadeInLeftAnimator());

//        /* Listeners */
//        recyclerView.setOnScrollListener(onScrollListener);
    }
 
Example #21
Source File: MediaItemDecoration.java    From FilePicker with MIT License 6 votes vote down vote up
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
                            int childCount) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
 
Example #22
Source File: BaseRecyclerOnScrollListener.java    From Meizi with Apache License 2.0 6 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    totalItemCount = layoutManager.getItemCount();
    visibleItemCount = recyclerView.getChildCount();
    if (layoutManager instanceof StaggeredGridLayoutManager) {
        ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(staggerLastVisibleItemPosition);
        lastVisibleItemPosition = findMax(staggerLastVisibleItemPosition);
    } else if (layoutManager instanceof LinearLayoutManager) {
        lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
    }

    if (loading) {
        if (totalItemCount - 1 > previousTotal) { //加载完数据而不是footer
            loading = false;
            previousTotal = totalItemCount;
        }
    }
    if (!loading && visibleItemCount > 0
            && lastVisibleItemPosition
            >= (totalItemCount - visibleThreshold)) {
        currentPage++;
        loading = true;
        onLoadMore(currentPage);
    }
}
 
Example #23
Source File: HobbyFragment.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view=inflater.inflate(R.layout.recycle_view, container, false);
    recyclerView=(BaseRecycleView)view.findViewById(R.id.recycle_view);
    list=new ArrayList<>();
    list.add(new HobbyArray(1,"",1,1));
    list.add(new HobbyArray(1,"",1,1));
    list.add(new HobbyArray(1,"",1,1));
    adapter=new MyAdapter();
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL));
    TextView empty=(TextView)view.findViewById(R.id.empty_view);
    empty.setText("似乎没什么感兴趣的呢");
    recyclerView.setEmptyView(empty);
    recyclerView.setAdapter(adapter);
    return view;
}
 
Example #24
Source File: RecyclerViewElasticityAdapter.java    From elasticity with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public RecyclerViewElasticityAdapter(RecyclerView recyclerView) {

        mRecyclerView = recyclerView;

        final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        if (layoutManager instanceof LinearLayoutManager ||
            layoutManager instanceof StaggeredGridLayoutManager)
        {
            final int orientation =
                    (layoutManager instanceof LinearLayoutManager
                        ? ((LinearLayoutManager) layoutManager).getOrientation()
                        : ((StaggeredGridLayoutManager) layoutManager).getOrientation());

            if (orientation == LinearLayoutManager.HORIZONTAL) {
                mImpl = new ImplHorizLayout();
            } else {
                mImpl = new ImplVerticalLayout();
            }
        }
        else
        {
            throw new IllegalArgumentException("Recycler views with custom layout managers are not supported by this adapter out of the box." +
                    "Try implementing and providing an explicit 'impl' parameter to the other c'tors, or otherwise create a custom adapter subclass of your own.");
        }
    }
 
Example #25
Source File: ViewUtils.java    From VideoMeeting with Apache License 2.0 6 votes vote down vote up
public static int getLastVisiblePosition(RecyclerView recyclerView) {
	RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
	int position;
       if (manager instanceof GridLayoutManager) {
           position = ((GridLayoutManager) manager).findLastVisibleItemPosition();
       } else if (manager instanceof LinearLayoutManager) {
           position = ((LinearLayoutManager) manager).findLastVisibleItemPosition();
       } else if (manager instanceof StaggeredGridLayoutManager) {
           StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;
           int[] lastPositions = layoutManager.findLastVisibleItemPositions(new int[layoutManager.getSpanCount()]);
           position = getMaxPosition(lastPositions);
       } else {
           position = manager.getItemCount() - 1;
       }
       return position;
}
 
Example #26
Source File: BeerProductAdapter.java    From nongbeer-mvp-android-demo with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder( BaseViewHolder viewHolder, final int position ){
    super.onBindViewHolder( viewHolder, position );
    BaseItem i = getPresenter().getItem( position );
    if( getItemViewType( position ) == TYPE_BEER_PRODUCT ){
        final BeerProductItem item = (BeerProductItem) i;
        BeerProductHolder holder = (BeerProductHolder) viewHolder;
        holder.onBind( item );
        holder.setOnClickBeerListener( onClickBeer( item ) );
    }else if( getItemViewType( position ) == BaseItemType.TYPE_PROGRESS ){
        StaggeredGridLayoutManager.LayoutParams layoutParams =
                (StaggeredGridLayoutManager.LayoutParams) viewHolder.itemView.getLayoutParams();
        layoutParams.setFullSpan( true );
        viewHolder.itemView.setLayoutParams( layoutParams );
    }
}
 
Example #27
Source File: MediaItemDecoration.java    From AndroidDownload with Apache License 2.0 6 votes vote down vote up
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
                            int childCount) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
 
Example #28
Source File: OrgDetailFragment.java    From GSoC-Info-Android with GNU General Public License v2.0 5 votes vote down vote up
@Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_org_details,container,false);
        Intent i = getActivity().getIntent();
        Organization organization = (Organization) i.getSerializableExtra(ORG_TAG);

        TextView orgDetails = view.findViewById(R.id.org_detail_details);
        TextView orgTitle = view.findViewById(R.id.org_detail_title);

        AndDown andDown=new AndDown();

        String orgDesc = organization.getDescription();
//                .replaceAll("(\\? )|(\\! )|(\\. )", "$0\n"); //Replace every period with newline

        orgDesc = andDown.markdownToHtml(orgDesc);  //Todo : do this while inserting to db

        orgDetails.setText(Html.fromHtml(orgDesc));
        orgTitle.setText(organization.getTagline());
        RecyclerView techRv = view.findViewById(R.id.techTagRecyclerView);
        TagAdapter techAdapter;
        List<String> tags = new ArrayList<>();

        tags.addAll(organization.getTechnologyTags());
        tags.addAll(organization.getTopicTags());
        tags.addAll(organization.getProposalTags());
        techAdapter = new TagAdapter(tags);

        techRv.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.HORIZONTAL));
        techRv.setAdapter(techAdapter);

        return view;
    }
 
Example #29
Source File: BaseAdapter.java    From NiceRead with Apache License 2.0 5 votes vote down vote up
/**
 * StaggeredGridLayoutManager模式时,FooterView可占据一行
 *
 * @param holder
 */
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
    super.onViewAttachedToWindow(holder);
    if (isFooterView(holder.getLayoutPosition())) {
        ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();

        if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) {
            StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
            p.setFullSpan(true);
        }
    }
}
 
Example #30
Source File: ClassifiesShowActivity.java    From HHComicViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onSuccess(final int maxPage, final List<Comic> comics) {
    mMaxPage = maxPage;
    mComicList.addAll(comics);
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (mAdapter == null) {
                MyStaggerLayoutManager layoutManager = new MyStaggerLayoutManager(3,
                        StaggeredGridLayoutManager.VERTICAL);
                layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                mBinding.recyclerView.setLayoutManager(layoutManager);
                mBinding.recyclerView.setItemAnimator(new DefaultItemAnimator());
                mInnerAdapter = new StaggeredComicAdapter(ClassifiesShowActivity.this, null, mComicList);
                mAdapter = new StaggeredComicAdapterWrapper(mInnerAdapter);
                mBinding.recyclerView.setAdapter(mAdapter);
                mBinding.recyclerView.setVisibility(View.VISIBLE);
                mBinding.progressBar.setVisibility(View.GONE);
            } else {
                mInnerAdapter.updateComicList(mComicList);
                if (mMaxPage == mPage) {
                    mBinding.recyclerView.setNoMore(true);
                } else {
                    //参数为每页加载数量
                    mBinding.recyclerView.refreshComplete(comics.size());
                }
                mAdapter.notifyDataSetChanged();
            }
        }
    });
}