Search in sources :

Example 51 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project BGARefreshLayout-Android by bingoogolapple.

the class BGARefreshScrollingUtil method isRecyclerViewToTop.

public static boolean isRecyclerViewToTop(RecyclerView recyclerView) {
    if (recyclerView != null) {
        RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
        if (manager == null) {
            return true;
        }
        if (manager.getItemCount() == 0) {
            return true;
        }
        if (manager instanceof LinearLayoutManager) {
            LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
            int firstChildTop = 0;
            if (recyclerView.getChildCount() > 0) {
                // 处理item高度超过一屏幕时的情况
                View firstVisibleChild = recyclerView.getChildAt(0);
                if (firstVisibleChild != null && firstVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) {
                    if (android.os.Build.VERSION.SDK_INT < 14) {
                        return !(ViewCompat.canScrollVertically(recyclerView, -1) || recyclerView.getScrollY() > 0);
                    } else {
                        return !ViewCompat.canScrollVertically(recyclerView, -1);
                    }
                }
                // 如果RecyclerView的子控件数量不为0,获取第一个子控件的top
                // 解决item的topMargin不为0时不能触发下拉刷新
                View firstChild = recyclerView.getChildAt(0);
                RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) firstChild.getLayoutParams();
                firstChildTop = firstChild.getTop() - layoutParams.topMargin - getRecyclerViewItemTopInset(layoutParams) - recyclerView.getPaddingTop();
            }
            if (layoutManager.findFirstCompletelyVisibleItemPosition() < 1 && firstChildTop == 0) {
                return true;
            }
        } else if (manager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;
            int[] out = layoutManager.findFirstCompletelyVisibleItemPositions(null);
            if (out[0] < 1) {
                return true;
            }
        }
    }
    return false;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) View(android.view.View) WebView(android.webkit.WebView)

Example 52 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project baseAdapter by hongyangAndroid.

the class RecyclerViewActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    //noinspection SimplifiableIfStatement
    switch(id) {
        case R.id.action_linear:
            mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
            break;
        case R.id.action_grid:
            mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
            break;
        case R.id.action_staggered:
            mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
            break;
    }
    mRecyclerView.setAdapter(mLoadMoreWrapper);
    return super.onOptionsItemSelected(item);
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 53 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project SuperRecyclerView by Malinskiy.

the class SuperRecyclerView method caseStaggeredGrid.

private int caseStaggeredGrid(RecyclerView.LayoutManager layoutManager) {
    StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
    if (lastScrollPositions == null)
        lastScrollPositions = new int[staggeredGridLayoutManager.getSpanCount()];
    staggeredGridLayoutManager.findLastVisibleItemPositions(lastScrollPositions);
    return findMax(lastScrollPositions);
}
Also used : StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager)

Example 54 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 55 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project BaseRecyclerViewAdapterHelper by CymChad.

the class SectionUseActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_section_uer);
    setBackBtn();
    setTitle("Section Use");
    mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
    mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    mData = DataServer.getSampleData();
    SectionAdapter sectionAdapter = new SectionAdapter(R.layout.item_section_content, R.layout.def_section_head, mData);
    mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {

        @Override
        public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
            MySection mySection = mData.get(position);
            if (mySection.isHeader)
                Toast.makeText(SectionUseActivity.this, mySection.header, Toast.LENGTH_LONG).show();
            else
                Toast.makeText(SectionUseActivity.this, mySection.t.getName(), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
            Toast.makeText(SectionUseActivity.this, "onItemChildClick" + position, Toast.LENGTH_LONG).show();
        }
    });
    mRecyclerView.setAdapter(sectionAdapter);
}
Also used : MySection(com.chad.baserecyclerviewadapterhelper.entity.MySection) OnItemClickListener(com.chad.library.adapter.base.listener.OnItemClickListener) SectionAdapter(com.chad.baserecyclerviewadapterhelper.adapter.SectionAdapter) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)78 RecyclerView (android.support.v7.widget.RecyclerView)52 View (android.view.View)37 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)32 GridLayoutManager (android.support.v7.widget.GridLayoutManager)26 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)9 Handler (android.os.Handler)7 Toolbar (android.support.v7.widget.Toolbar)7 TextView (android.widget.TextView)7 Nullable (android.support.annotation.Nullable)5 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)5 ViewGroup (android.view.ViewGroup)5 AbsListView (android.widget.AbsListView)5 ScrollView (android.widget.ScrollView)5 BindView (butterknife.BindView)5 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 Bundle (android.os.Bundle)3 FloatingActionButton (android.support.design.widget.FloatingActionButton)3