Java 类android.support.v7.widget.StaggeredGridLayoutManager 实例源码

项目:Instincts-2k17    文件:GalleryActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    ActivityCompat.setExitSharedElementCallback(this, exitTransitionCallback);
    super.onCreate(savedInstanceState);

    int mUIFlag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LOW_PROFILE
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

    getWindow().getDecorView().setSystemUiVisibility(mUIFlag);

    setContentView(R.layout.activity_gallery);
    ButterKnife.bind(this);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    ArrayList<String> imagesList = new ArrayList<>();
    for (int i = 1; i <= 23; i++)
        imagesList.add("http://ssninstincts.org.in/img/gallery/big/" + i + ".jpg");

    galleryAdapter = new GalleryAdapter(this, imagesList);
    StaggeredGridLayoutManager gridLayoutManager =
            new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    gridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
    galleryRecyclerView.setHasFixedSize(true);
    galleryRecyclerView.setLayoutManager(gridLayoutManager);
    galleryRecyclerView.setAdapter(galleryAdapter);
}
项目:JsoupSample    文件:PtFictionMoreActivity.java   
private void initRecyclerView() {
    mAdapter = new XRecyclerViewAdapter<>();
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    recyclerView.setLoadingMore(this);
    recyclerView.setAdapter(
            mAdapter
                    .setLayoutId(R.layout.item_fiction_pt_list)
                    .setOnItemClickListener((view, position, info) -> {
                        String detailUrl = info.detailUrl;
                        if (TextUtils.isEmpty(detailUrl)) {
                            UIUtils.snackBar(mStatusView, R.string.pt_list_content_error);
                            return;
                        }
                        String bookinfo = detailUrl.replaceAll(".html", "/index.html").replaceAll("bookinfo", "html");
                        if (TextUtils.isEmpty(bookinfo)) {
                            UIUtils.snackBar(mStatusView, R.string.pt_list_content_error);
                            return;
                        }
                        FictionContentsActivity.getInstance(ApiConfig.Type.PIAO_TIAN, bookinfo, info.title);
                    })
                    .onXBind((holder, position, fictionModel) -> holder.setTextView(R.id.tv_title, fictionModel.title))
    );
}
项目:SIIEScanner    文件:ItemSenderUser.java   
public ItemSenderUser(View itemView) {
    super(itemView);

    //Load fields
    this.tvClientName = (TextView) itemView.findViewById( R.id.tv_client_name );

    this.imageView = (ImageView) this.itemView.findViewById(R.id.iv_profile);
    //Set on click
    this.imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            click();
        }
    });
    StaggeredGridLayoutManager.LayoutParams st = (StaggeredGridLayoutManager.LayoutParams) this.itemView.getLayoutParams();
}
项目:LowRecyclerView    文件:RecyclerViewUtils.java   
private void setRecyclerStlty() {
    switch (mAdapter.getmStyle()) {
        case ListView:
        case HorizontalListView:
            setLView();
            break;
        case GridView:
        case HorizontalGridView:
            setGView();
            break;
        case WaterFall:
            StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(mNunColumns, StaggeredGridLayoutManager.VERTICAL);
            mRecyclerView.setLayoutManager(manager);
            break;
        case HorizontalWaterFall:
            StaggeredGridLayoutManager manager1 = new StaggeredGridLayoutManager(mNunColumns, StaggeredGridLayoutManager.HORIZONTAL);
            mRecyclerView.setLayoutManager(manager1);
            break;
        case MultiLayout:
            //多布局暂未实现
            break;

    }

}
项目:LuaViewPlayground    文件:UDBaseRecyclerView.java   
/**
 * TODO 支持offset
 *
 * @param section
 * @param rowInSection
 * @param offset
 * @param animate
 * @return
 */
@Override
public UDBaseListOrRecyclerView scrollToItem(int section, int rowInSection, int offset, boolean animate) {
    final 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;
}
项目:CommonFramework    文件:DividerGridItemDecoration.java   
private boolean isLastRow(RecyclerView parent, int pos, int rowCount, int childCount) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        childCount = childCount - childCount % rowCount;
        if (pos >= childCount) { // 如果是最后一行,则不需要绘制底部分割线
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            childCount = childCount - childCount % rowCount;
            if (pos >= childCount) { // 如果是最后一行,则不需要绘制底部分割线
                return true;
            }
        } else {
            if ((pos + 1) % rowCount == 0) { // 如果是最后一行,则不需要绘制底部分割线
                return true;
            }
        }
    }
    return false;
}
项目:CommonFramework    文件:DividerGridItemDecoration.java   
private boolean isLastColumn(RecyclerView parent, int pos, int rowCount, int childCount) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % rowCount == 0) { // 如果是最后一列,则不需要绘制右侧分割线
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % rowCount == 0) { // 如果是最后一列,则不需要绘制右侧分割线
                return true;
            }
        } else {
            childCount = childCount - childCount % rowCount;
            if (pos >= childCount) { // 如果是最后一列,则不需要绘制右侧分割线
                return true;
            }
        }
    }

    return false;
}
项目:boohee_v5.6    文件:DividerGridItemDecoration.java   
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;
}
项目:JsoupSample    文件:PtFictionHomeFragment.java   
@Override
protected void initActivityCreated() {
    if (!isPrepared || !isVisible || isLoad) {
        return;
    }
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.post(this::onRefresh);
    swipeRefreshLayout.setEnabled(false);
    mAdapter = new MultiAdapter<>(new ArrayList<>());
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    recyclerView.setAdapter(
            mAdapter.setXMultiAdapterListener(this)
    );

    setLoad();
}
项目:RecyclerViewEvent    文件:DividerGridItemDecoration.java   
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;
}
项目:popomusic    文件:KepuFragment.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_video_pager, container, false);
    listView = (RecyclerView) view.findViewById(R.id.list);
    listView.setHasFixedSize(true);
    listView.setLayoutManager(new StaggeredGridLayoutManager(1, LinearLayoutManager.VERTICAL));
    List<ItemList> lists = new ArrayList<ItemList>();
    videoadapter = new VideoAdapter(lists);
    listView.setAdapter(videoadapter);

    mPresent = new VideoPresenter((VideoData.View) this);

    srfLayout = (SwipeRefreshLayout) view.findViewById(R.id.srf_layout);
    srfLayout.setOnRefreshListener(this);
    srfLayout.post(() -> onRefresh());
    return view;
}
项目:Samantha    文件:RealmRecyclerView.java   
public int findFirstVisibleItemPosition() {
    switch (type) {
        case LinearLayout:
            return ((LinearLayoutManager) recyclerView.getLayoutManager())
                    .findFirstVisibleItemPosition();
        case Grid:
            return ((GridLayoutManager) recyclerView.getLayoutManager())
                    .findFirstVisibleItemPosition();
        case LinearLayoutWithHeaders:
            return ((LayoutManager) recyclerView.getLayoutManager())
                    .findFirstVisibleItemPosition();
        case StaggeredGridLayout:
            return ((StaggeredGridLayoutManager) recyclerView.getLayoutManager())
                    .findFirstVisibleItemPositions(null)[0];
        default:
            throw new IllegalStateException("Type of layoutManager unknown." +
                    "In this case this method needs to be overridden");
    }
}
项目:MultiSelecter    文件:SmartRecycleView.java   
public SmartRecycleView setLayoutManger(LayoutManagerType layoutManagerType, int orientation, int spanCout) {
    RecyclerView.LayoutManager layoutManager = null;
    if (layoutManagerType == LayoutManagerType.LINEAR_LAYOUT) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(orientation);
        layoutManager = linearLayoutManager;
    } else if (layoutManagerType == LayoutManagerType.GRID_LAYOUT) {
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, spanCout);
        gridLayoutManager.setOrientation(orientation);
        layoutManager = gridLayoutManager;
    } else if (layoutManagerType == LayoutManagerType.STAGGER_LAYOUT) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(spanCout, orientation);
        layoutManager = staggeredGridLayoutManager;
    }
    mRecyclerView.setLayoutManager(layoutManager);
    return this;
}
项目:AutoRecycleView    文件:SmartRecycleView.java   
public SmartRecycleView setLayoutManger(LayoutManagerType layoutManagerType, int orientation, int spanCout) {
    RecyclerView.LayoutManager layoutManager = null;
    if (layoutManagerType == LayoutManagerType.LINEAR_LAYOUT) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(orientation);
        layoutManager = linearLayoutManager;
    } else if (layoutManagerType == LayoutManagerType.GRID_LAYOUT) {
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, spanCout);
        gridLayoutManager.setOrientation(orientation);
        layoutManager = gridLayoutManager;
    } else if (layoutManagerType == LayoutManagerType.STAGGER_LAYOUT) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(spanCout, orientation);
        layoutManager = staggeredGridLayoutManager;
    }
    mRecyclerView.setLayoutManager(layoutManager);
    return this;
}
项目:popomusic    文件:YugaoFragment.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_video_pager, container, false);
    listView = (RecyclerView) view.findViewById(R.id.list);
    listView.setHasFixedSize(true);
    listView.setLayoutManager(new StaggeredGridLayoutManager(1, LinearLayoutManager.VERTICAL));
    List<ItemList> lists = new ArrayList<ItemList>();
    videoadapter = new VideoAdapter(lists);
    listView.setAdapter(videoadapter);

    mPresent = new VideoPresenter((VideoData.View) this);

    srfLayout = (SwipeRefreshLayout) view.findViewById(R.id.srf_layout);
    srfLayout.setOnRefreshListener(this);
    srfLayout.post(() -> onRefresh());
    return view;
}
项目:Mobike    文件:DividerGridItemDecoration.java   
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;
}
项目:Traveler-List    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

    toolbar = (Toolbar)findViewById(R.id.toolbarMainActivity);
    setUpActionBar();

  isListView = true;

  mStaggeredLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
  mRecyclerView = (RecyclerView)findViewById(R.id.list);

  mRecyclerView.setLayoutManager(mStaggeredLayoutManager);

  mAdapter = new TravelListAdapter(this);
  mRecyclerView.setAdapter(mAdapter);
  mAdapter.setOnItemClickListener(onItemClickListener);
}
项目:topnews    文件:TalkingFragment.java   
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    View view=View.inflate(UIUtils.getContext(), R.layout.talking_pager,null);

    mRecycler = (RecyclerView) view.findViewById(R.id.icon_recycler);
    layoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
    layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
    mRecycler.setLayoutManager(layoutManager);

    initData();

    initListener();

    return view;
}
项目:GitHub    文件:InfiniteLoadingHelper.java   
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
  if (dy > 0 && !loadingHelper.isLoading && loadingHelper.canLoadMore) {
    int totalItemCount = recyclerView.getLayoutManager().getItemCount();
    int lastVisibleItemPosition = 0;
    if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
      int[] lastVisibleItemPositions =
          ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPositions(
              null);
      lastVisibleItemPosition = lastVisibleItemPositions[lastVisibleItemPositions.length - 1];
    } else if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
      lastVisibleItemPosition =
          ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition();
    }

    if (lastVisibleItemPosition + 1 >= totalItemCount) {
      loadingHelper.loadNextPage();
    }
  }
}
项目:JD-Test    文件:PtrDefaultHandler.java   
public static boolean canChildScrollUp(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else if(view instanceof  RecyclerView){
            RecyclerView recyclerView = (RecyclerView)view;
            RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
            if(layoutManager instanceof LinearLayoutManager){
                int position = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
                return position != 0;
            }else{
                if(layoutManager instanceof StaggeredGridLayoutManager ){
                    StaggeredGridLayoutManager stagger = (StaggeredGridLayoutManager) layoutManager;
                    int[] positions = stagger.findFirstCompletelyVisibleItemPositions(null);
                    return positions[0] != 0;
                }else{
                    throw new RuntimeException("can not support this LayoutManager ");
                }
            }
        }else{
            return view.getScrollY() > 0;
        }
    } else {
        return view.canScrollVertically(-1);
    }
}
项目:GitHub    文件:DividerGridItemDecoration.java   
private int getSpanCount(RecyclerView parent)
{
    // 列数
    int spanCount = -1;
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        spanCount = ((StaggeredGridLayoutManager) layoutManager)
                .getSpanCount();
    }
    return spanCount;
}
项目:OpenEyesReading-android    文件:NewsActivity.java   
private int calculateRecyclerViewFirstPosition() {
    RecyclerView.LayoutManager manager = mRecyclerView.getLayoutManager();
    if (manager instanceof StaggeredGridLayoutManager) {
        if (mVisiblePositions == null)
            mVisiblePositions = new int[((StaggeredGridLayoutManager) manager).getSpanCount()];
        ((StaggeredGridLayoutManager) manager).findLastCompletelyVisibleItemPositions(mVisiblePositions);
        int max = -1;
        for (int pos : mVisiblePositions) {
            max = Math.max(max, pos);
        }
        return max;
    } else if (manager instanceof GridLayoutManager) {
        return ((GridLayoutManager) manager).findFirstCompletelyVisibleItemPosition();
    } else {
        return ((LinearLayoutManager) manager).findLastCompletelyVisibleItemPosition();
    }
}
项目:GitHub    文件:AbstractFragment.java   
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_list_type) {
        if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
            mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
            item.setIcon(R.drawable.ic_view_grid_white_24dp);
            item.setTitle(R.string.grid_layout);//next click
            showNewLayoutInfo(item);
        } else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
            mRecyclerView.setLayoutManager(createNewStaggeredGridLayoutManager());
            item.setIcon(R.drawable.ic_view_agenda_white_24dp);
            item.setTitle(R.string.linear_layout);//next click
            showNewLayoutInfo(item);
        } else {
            mRecyclerView.setLayoutManager(createNewGridLayoutManager());
            item.setIcon(R.drawable.ic_dashboard_white_24dp);
            item.setTitle(R.string.staggered_layout);//next click
            showNewLayoutInfo(item);
        }
    }
    return super.onOptionsItemSelected(item);
}
项目:aarLibrary    文件:Utils.java   
public static int findFirstCompletelyVisibleItemPosition(RecyclerView recyclerView) {
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int firstPosition;
    if (layoutManager instanceof LinearLayoutManager) {
        firstPosition = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
    } else if (layoutManager instanceof GridLayoutManager) {
        firstPosition = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
        int[] lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
        staggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions(lastPositions);
        firstPosition = findMin(lastPositions);
    } else {
        throw new RuntimeException(
                "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
    }
    return firstPosition;
}
项目:GitHub    文件:FragmentOverall.java   
@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    MenuItem gridMenuItem = menu.findItem(R.id.action_list_type);
    if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
        gridMenuItem.setIcon(R.drawable.ic_view_agenda_white_24dp);
        gridMenuItem.setTitle(R.string.linear_layout);
    } else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
        gridMenuItem.setIcon(R.drawable.ic_dashboard_white_24dp);
        gridMenuItem.setTitle(R.string.staggered_layout);
    } else {
        gridMenuItem.setIcon(R.drawable.ic_view_grid_white_24dp);
        gridMenuItem.setTitle(R.string.grid_layout);
    }
}
项目:BookReader-master    文件:SupportGridItemDecoration.java   
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;
}
项目:GitHub    文件:ScrollableUseCaseItem.java   
public UCViewHolder(View view, FlexibleAdapter adapter) {
    super(view, adapter);
    mTitle = (TextView) view.findViewById(R.id.title);
    mSubtitle = (TextView) view.findViewById(R.id.subtitle);
    mDismissIcon = (ImageView) view.findViewById(R.id.dismiss_icon);
    mDismissIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Don't need anymore to set permanent deletion for Scrollable Headers and Footers
            //mAdapter.setPermanentDelete(true);
            //noinspection unchecked, ConstantConditions
            mAdapter.removeScrollableHeader(mAdapter.getItem(getAdapterPosition()));
            //mAdapter.setPermanentDelete(false);
        }
    });

    //Support for StaggeredGridLayoutManager
    if (itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
        ((StaggeredGridLayoutManager.LayoutParams) itemView.getLayoutParams()).setFullSpan(true);
    }
}
项目:MTweaks-KernelAdiutorMOD    文件:RecyclerViewFragment.java   
protected void addItem(RecyclerViewItem recyclerViewItem) {
    if (mItems.size() == 0 && mAdView != null && !mItems.contains(mAdView)) {
        boolean exists = false;
        for (RecyclerViewItem item : mItems) {
            if (item instanceof AdView) {
                exists = true;
                break;
            }
        }
        if (!exists) {
            mItems.add(mAdView);
        }
    }
    mItems.add(recyclerViewItem);
    if (mRecyclerViewAdapter != null) {
        mRecyclerViewAdapter.notifyItemInserted(mItems.size() - 1);
    }
    if (mLayoutManager instanceof StaggeredGridLayoutManager) {
        ((StaggeredGridLayoutManager) mLayoutManager).setSpanCount(getSpanCount());
    }
}
项目:OpenEyesReading-android    文件:PhotoListFrag.java   
private void initNewList(List<SinaPhotosList.DataEntity.PhotoListEntity> data) {
    final StaggeredGridLayoutManager sta = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    mAdapter = new BaseRecyclerAdapter<SinaPhotosList.DataEntity.PhotoListEntity>(getActivity(), data) {

        Random random = new Random();

        @Override
        public int getItemViewId() {
            return R.layout.item_photo_summary;
        }

        @Override
        public void bindData(BaseRecyclerViewHolder holder, int position, SinaPhotosList.DataEntity.PhotoListEntity item) {
            final ImageView imageView = (ImageView) holder.getView(R.id.iv_photo_summary);
            final TextView textView = (TextView) holder.getView(R.id.tv_photo_summary);
            final ViewGroup.LayoutParams params = imageView.getLayoutParams();
            if (item.picWidth == -1 && item.picHeight == -1) {
                item.picWidth = MeasureUtils.getScreenSize(getActivity()).x / 2 - MeasureUtils.dp2px(getActivity(), 4) * 2 - MeasureUtils.dp2px(getActivity(), 2);
                item.picHeight = (int) (item.picWidth * (random.nextFloat() / 2 + 1));
            }
            params.width = item.picWidth;
            params.height = item.picHeight;
            imageView.setLayoutParams(params);
            textView.setText(item.title);
            ImageLoader.getInstance().displayImage(item.kpic, imageView, App.getDefaultOptionsBuilder());
        }
    };
    mAdapter.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void OnItemClick(View view, int position) {
            Intent intent = new Intent(getActivity(), SinaPhotoDetailActivity.class);
            intent.putExtra("photoId", mAdapter.getDatas().get(position).id);
            ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(view, view.getWidth() / 2, view.getHeight() / 2, 0, 0);
            ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
        }
    });
    mRecyclerView.setLayoutManager(sta);
    mRecyclerView.addItemDecoration(new BaseSpacesItemDecoration(MeasureUtils.dp2px(getActivity(), 4), false));
    mRecyclerView.setAdapter(mAdapter);
}
项目:android-advanced-light    文件:RecyclerViewActivity.java   
public void setGridView(){
    mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(4,
            StaggeredGridLayoutManager.VERTICAL));
    mRecyclerView.addItemDecoration(new DividerGridItemDecoration(this));
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mHomeAdaper=new HomeAdapter(this, mList);
    setLister();
    mRecyclerView.setAdapter(mHomeAdaper);
}
项目:AmenEye    文件:BaseRecyclerAdapter.java   
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
    super.onViewAttachedToWindow(holder);
    if ((holder.getItemViewType() == TYPE_HEADER.getiNum()) ||
            (holder.getItemViewType() == TYPE_FOOTER.getiNum()) ||
            (holder.getItemViewType() == TYPE_TAGS.getiNum())) {
        ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
        if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) {
            StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
            p.setFullSpan(true);
        }
    }
}
项目:baselibrary-master    文件:LoadMoreWrapper.java   
private void setFullSpan(RecyclerView.ViewHolder holder)
{
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();

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

        p.setFullSpan(true);
    }
}
项目:UiLib    文件:LRecyclerView.java   
@Override
public void onScrollStateChanged(int state) {
    super.onScrollStateChanged(state);
    if (state == RecyclerView.SCROLL_STATE_IDLE && mLoadingListener != null && !isLoadingData && loadingMoreEnabled) {
        LayoutManager layoutManager = getLayoutManager();
        int lastVisibleItemPosition;
        if (layoutManager instanceof GridLayoutManager) {
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            int[] into = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
            ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(into);
            lastVisibleItemPosition = findMax(into);
        } else {
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
        }
        if (layoutManager.getChildCount() > 0
                && lastVisibleItemPosition >= layoutManager.getItemCount() - 1 && layoutManager.getItemCount() > layoutManager.getChildCount() && !isNoMore && mRefreshHeader.getState() < ArrowRefreshHeader.STATE_REFRESHING) {
            isLoadingData = true;
            if (mFootView instanceof LoadingMoreFooter) {
                ((LoadingMoreFooter) mFootView).setState(LoadingMoreFooter.STATE_LOADING);
            } else {
                mFootView.setVisibility(View.VISIBLE);
            }
            mLoadingListener.onLoadMore();
        }
    }
}
项目:popomusic    文件:CeshiFragment.java   
protected void initData() {
    listView.setHasFixedSize(true);
    listView.setLayoutManager(new StaggeredGridLayoutManager(1, LinearLayoutManager.VERTICAL));

    List<ItemList> lists=new ArrayList<ItemList>();

    mPresent=new VideoPresenter((VideoData.View) this);
    videoadapter=new VideoAdapter(lists);
    listView.setAdapter(videoadapter);

    srfLayout.setOnRefreshListener(this);
    srfLayout.post(() -> onRefresh());
}
项目:LuaViewPlayground    文件:DividerGridItemDecoration.java   
/**
 * get total Span Count
 *
 * @param parent
 * @return
 */
private int getSpanCount(RecyclerView parent) {
    int spanCount = -1;
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        spanCount = ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
    }
    return spanCount;
}
项目:TextReader    文件:SupportGridItemDecoration.java   
private int getSpanCount(RecyclerView parent) {
    // 列数
    int spanCount = -1;
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        spanCount = ((StaggeredGridLayoutManager) layoutManager)
                .getSpanCount();
    }
    return spanCount;
}
项目:moebooru-android    文件:PostSearchActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_post_search);

    mRecyclerView = (RecyclerView) findViewById(R.id.rv_post_search);
    mLayoutManager = new StaggeredGridLayoutManager(SPAN_COUNT, StaggeredGridLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mSwipeRefreshLayout = findViewById(R.id.scroll_view_search);
    mSwipeRefreshLayout.setColorSchemeResources(
            android.R.color.holo_blue_bright,
            android.R.color.holo_green_light,
            android.R.color.holo_orange_light,
            android.R.color.holo_red_light);
    mAdapter = new PostViewAdapter(mListener, "search");
    mRecyclerView.setAdapter(mAdapter);

    mTAGS = getSelectedTags();
    initRefreshListener();
    initScrollListener();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_search);
    toolbar.setSubtitle(mTAGS);

    mSwipeRefreshLayout.setRefreshing(true);
    new PullPost(0, mPAGE).execute();

    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    new AnalyticsUtils().getAnalytics(TAG, mTAGS, "search" ,mFirebaseAnalytics);
}
项目:InstaFlickr    文件:UserProfileActivity.java   
private void setupUserProfileGrid() {
    final StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);//瀑布流图片浏览
    rvUserProfile.setLayoutManager(layoutManager);
    rvUserProfile.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            //userPhotosAdapter.setLockedAnimations(true);
        }
    });
}
项目:AmenEye    文件:VideoInfoFragment.java   
private void initView() {
    mBaseItems = new ArrayList<>();
    mFoldableTextView = (FoldableTextView) mMrvRecommend.getHeaderView().findViewById(R.id.ftv_content_text);
    mMrvRecommend.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
    mMrvRecommend.setItemAnimator(new DefaultItemAnimator());
    mMrvRecommend.getItemAnimator().setChangeDuration(0);
    SpaceDecoration itemDecoration = new SpaceDecoration(DensityUtil.dip2px(getContext(), 8));
    itemDecoration.setPaddingEdgeSide(true);
    itemDecoration.setPaddingStart(true);
    itemDecoration.setPaddingHeaderFooter(false);
    mMrvRecommend.addItemDecoration(itemDecoration);
    currentId = getArguments().getString(Constants.BUNDLE_KEY_DATAID);
    loadInfo();
}
项目:PullToRefreshRecyclerView    文件:PullToRefreshRecyclerView.java   
private int getFirstVisiblePosition() {
    int position;
    if (getLayoutManager() instanceof LinearLayoutManager) {
        position = ((LinearLayoutManager) getLayoutManager()).findFirstCompletelyVisibleItemPosition();
    } else if (getLayoutManager() instanceof GridLayoutManager) {
        position = ((GridLayoutManager) getLayoutManager()).findFirstCompletelyVisibleItemPosition();
    } else {
        StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) getLayoutManager();
        int[] firstPositions =
                layoutManager.findFirstCompletelyVisibleItemPositions(new int[layoutManager.getSpanCount()]);
        position = getMinPosition(firstPositions);
    }
    return position;
}