Search in sources :

Example 91 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project BestPracticeApp by pop1234o.

the class RecyclerViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view);
    RecyclerView recycer = (RecyclerView) findViewById(R.id.recycer);
    // recycer.setLayoutManager(new LinearLayoutManager(this));
    // recycer.setLayoutManager(new GridLayoutManager(this,3));
    recycer.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    adapter = new RecyclerView.Adapter<ListHolder>() {

        @Override
        public ListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.list_recycle, null);
            view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            ListHolder listHolder = new ListHolder(view);
            return listHolder;
        }

        @Override
        public void onBindViewHolder(ListHolder holder, int position) {
            holder.setData(position);
        }

        @Override
        public int getItemCount() {
            return 50;
        }
    };
    recycer.setAdapter(adapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ListCallback());
    itemTouchHelper.attachToRecyclerView(recycer);
}
Also used : ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) ViewGroup(android.view.ViewGroup) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 92 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidNews by zhjohow.

the class PhotosFragment method initView.

@Override
public void initView() {
    if (getArguments() != null) {
        mPhotoType = getArguments().getString(AppConstant.PHOTO_TYPE);
    }
    adapter = new CommonRecycleViewAdapter<PhotoGirl>(getContext(), R.layout.item_photo) {

        @Override
        public void convert(ViewHolderHelper helper, final PhotoGirl photoGirl) {
            ImageView imageView = helper.getView(R.id.iv_photo);
            Glide.with(mContext).load(photoGirl.getThumbUrl()).diskCacheStrategy(DiskCacheStrategy.SOURCE).placeholder(R.drawable.ic_image_loading).error(R.drawable.ic_empty_picture).centerCrop().override(1090, 1090 * 3 / 4).crossFade().into(imageView);
            imageView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    PhotosDetailActivity.startAction(mContext, photoGirl.getThumbUrl());
                }
            });
        }
    };
    irc.setAdapter(adapter);
    irc.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    irc.setOnLoadMoreListener(this);
    irc.setOnRefreshListener(this);
    // fab.setOnClickListener(new View.OnClickListener() {
    // @Override
    // public void onClick(View view) {
    // irc.smoothScrollToPosition(0);
    // }
    // });
    mPresenter.getPhotosListDataRequest(mPhotoType, SIZE, mStartPage);
}
Also used : ViewHolderHelper(com.aspsine.irecyclerview.universaladapter.ViewHolderHelper) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) ImageView(android.widget.ImageView) IRecyclerView(com.aspsine.irecyclerview.IRecyclerView) ImageView(android.widget.ImageView) LoadMoreFooterView(com.aspsine.irecyclerview.widget.LoadMoreFooterView) View(android.view.View) PhotoGirl(com.zhjh.androidnews.bean.PhotoGirl)

Example 93 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project remusic by aa112901.

the class SwipeRefreshLayout method isChildScrollToBottom.

/**
 * 是否滑动到底部
 *
 * @return
 */
public boolean isChildScrollToBottom() {
    if (isChildScrollToTop()) {
        return false;
    }
    if (mTarget instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) mTarget;
        LayoutManager layoutManager = recyclerView.getLayoutManager();
        int count = recyclerView.getAdapter().getItemCount();
        if (layoutManager instanceof LinearLayoutManager && count > 0) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
            if (linearLayoutManager.findLastCompletelyVisibleItemPosition() == count - 1) {
                return true;
            }
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            int[] lastItems = new int[2];
            staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(lastItems);
            int lastItem = Math.max(lastItems[0], lastItems[1]);
            if (lastItem == count - 1) {
                return true;
            }
        }
        return false;
    } else if (mTarget instanceof AbsListView) {
        final AbsListView absListView = (AbsListView) mTarget;
        int count = absListView.getAdapter().getCount();
        int fristPos = absListView.getFirstVisiblePosition();
        if (fristPos == 0 && absListView.getChildAt(0).getTop() >= absListView.getPaddingTop()) {
            return false;
        }
        int lastPos = absListView.getLastVisiblePosition();
        if (lastPos > 0 && count > 0 && lastPos == count - 1) {
            return true;
        }
        return false;
    } else if (mTarget instanceof ScrollView) {
        ScrollView scrollView = (ScrollView) mTarget;
        View view = (View) scrollView.getChildAt(scrollView.getChildCount() - 1);
        if (view != null) {
            int diff = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));
            if (diff == 0) {
                return true;
            }
        }
    }
    return false;
}
Also used : ScrollView(android.widget.ScrollView) LayoutManager(android.support.v7.widget.RecyclerView.LayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 94 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project Collar by CodeZsx.

the class EndlessRecyclerViewOnScrollListener method onScrolled.

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager != null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LINEARLAYOUT;
        } else if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = GRIDLAYOUT;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = STAGGEREDGRIDLAYOUT;
        } else {
            throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }
    switch(layoutManagerType) {
        case LINEARLAYOUT:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GRIDLAYOUT:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case STAGGEREDGRIDLAYOUT:
            StaggeredGridLayoutManager staggeredGridLayoutManager = ((StaggeredGridLayoutManager) layoutManager);
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = lastPositions[0];
            for (int value : lastPositions) {
                lastVisibleItemPosition = value > lastVisibleItemPosition ? value : lastVisibleItemPosition;
            }
            break;
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 95 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project weiui by kuaifan.

the class RecylerOnBottomScrollListener method onScrolled.

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
        } else {
            throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }
    switch(layoutManagerType) {
        case LINEAR:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GRID:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case STAGGERED_GRID:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = findMax(lastPositions);
            break;
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)125 RecyclerView (android.support.v7.widget.RecyclerView)76 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)62 View (android.view.View)50 GridLayoutManager (android.support.v7.widget.GridLayoutManager)38 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)11 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)10 TextView (android.widget.TextView)10 Handler (android.os.Handler)9 BindView (butterknife.BindView)9 Intent (android.content.Intent)8 Nullable (android.support.annotation.Nullable)8 AbsListView (android.widget.AbsListView)8 ArrayList (java.util.ArrayList)8 ViewGroup (android.view.ViewGroup)6 WebView (android.webkit.WebView)6 ScrollView (android.widget.ScrollView)6 List (java.util.List)5 SuppressLint (android.annotation.SuppressLint)4 Point (android.graphics.Point)4