Search in sources :

Example 6 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project FlexibleAdapter by davideas.

the class ExampleAdapter method showLayoutInfo.

/*
	 * HEADER VIEW
	 * This method shows how to add Header View as it was for ListView.
	 * Same Header item is enqueued for removal with a delay.
	 * The view is represented by a custom Item type to better represent any dynamic content.
	 */
public void showLayoutInfo(boolean scrollToPosition) {
    if (!hasSearchText()) {
        final ScrollableLayoutItem item = new ScrollableLayoutItem("LAY-L");
        if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
            item.setId("LAY-S");
            item.setTitle(mRecyclerView.getContext().getString(R.string.staggered_layout));
        } else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
            item.setId("LAY-G");
            item.setTitle(mRecyclerView.getContext().getString(R.string.grid_layout));
        } else {
            item.setTitle(mRecyclerView.getContext().getString(R.string.linear_layout));
        }
        item.setSubtitle(mRecyclerView.getContext().getString(R.string.columns, String.valueOf(Utils.getSpanCount(mRecyclerView.getLayoutManager()))));
        // NOTE: If you have to change at runtime the LayoutManager AND add
        // Scrollable Headers, consider to add them in post, using a delay >= 0
        // otherwise scroll animations on all items will not start correctly.
        addScrollableHeaderWithDelay(item, 1200L, scrollToPosition);
        removeScrollableHeaderWithDelay(item, 4000L);
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) ScrollableLayoutItem(eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager)

Example 7 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project Reader by TheKeeperOfPie.

the class FragmentHistory method resetAdapter.

private void resetAdapter(AdapterLink newAdapter) {
    RecyclerView.LayoutManager layoutManagerCurrent = recyclerHistory.getLayoutManager();
    int size = layoutManagerCurrent instanceof StaggeredGridLayoutManager ? ((StaggeredGridLayoutManager) layoutManagerCurrent).getSpanCount() : 1;
    int[] currentPosition = new int[size];
    if (layoutManagerCurrent instanceof LinearLayoutManager) {
        currentPosition[0] = ((LinearLayoutManager) layoutManagerCurrent).findFirstVisibleItemPosition();
    } else if (layoutManagerCurrent instanceof StaggeredGridLayoutManager) {
        ((StaggeredGridLayoutManager) layoutManagerCurrent).findFirstCompletelyVisibleItemPositions(currentPosition);
    }
    this.adapterLink = newAdapter;
    this.layoutManager = adapterLink.getLayoutManager();
    if (layoutManager instanceof LinearLayoutManager) {
        recyclerHistory.setPadding(0, 0, 0, 0);
    } else {
        int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
        recyclerHistory.setPadding(padding, 0, padding, 0);
    }
    /*
            Note that we must call setAdapter before setLayoutManager or the ViewHolders
            will not be properly recycled, leading to memory leaks.
         */
    recyclerHistory.setAdapter(adapterLink);
    recyclerHistory.setLayoutManager(layoutManager);
    recyclerHistory.scrollToPosition(currentPosition[0]);
    if (layoutManager instanceof LinearLayoutManager) {
        recyclerHistory.addItemDecoration(itemDecorationDivider);
    } else {
        recyclerHistory.removeItemDecoration(itemDecorationDivider);
    }
}
Also used : LayoutManager(android.support.v7.widget.RecyclerView.LayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 8 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project FastDev4Android by jiangqqlmj.

the class RecyclerViewTestActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recyclerview_test_layout);
    top_bar_linear_back = (LinearLayout) this.findViewById(R.id.top_bar_linear_back);
    btn_add = (Button) this.findViewById(R.id.btn_add);
    btn_delete = (Button) this.findViewById(R.id.btn_delete);
    top_bar_linear_back.setOnClickListener(new CustomOnClickListener());
    btn_add.setOnClickListener(new CustomOnClickListener());
    btn_delete.setOnClickListener(new CustomOnClickListener());
    top_bar_title = (TextView) this.findViewById(R.id.top_bar_title);
    top_bar_title.setText("RecyclerView使用实例");
    //开始设置RecyclerView
    recyclerView_one = (RecyclerView) this.findViewById(R.id.recyclerView_one);
    recyclerView_one.setHasFixedSize(true);
    //1.LinearLayoutManager 线性布局类型
    mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setOrientation(OrientationHelper.VERTICAL);
    recyclerView_one.setLayoutManager(mLayoutManager);
    //2.GridLayoutManager 表格布局类型
    //        GridLayoutManager girdLayoutManager=new GridLayoutManager(this,4);
    //        recyclerView_one.setLayoutManager(girdLayoutManager);
    //3.采用StaggeredGridLayoutManager  流式布局类型
    //        StaggeredGridLayoutManager staggeredGridLayoutManager=new StaggeredGridLayoutManager(2,OrientationHelper.VERTICAL);
    //        recyclerView_one.setLayoutManager(staggeredGridLayoutManager);
    //添加默认的动画效果
    recyclerView_one.setItemAnimator(new DefaultItemAnimator());
    //添加分隔线
    recyclerView_one.addItemDecoration(new AdvanceDecoration(this, OrientationHelper.VERTICAL));
    mAdapter = new TestRecyclerAdapter(this, new TestRecyclerAdapter.OnRecyclerItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            Toast.makeText(RecyclerViewTestActivity.this, "点击了第" + position + "项", Toast.LENGTH_SHORT).show();
        }
    });
    recyclerView_one.setAdapter(mAdapter);
}
Also used : AdvanceDecoration(com.chinaztt.fda.widget.AdvanceDecoration) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) TestRecyclerAdapter(com.chinaztt.fda.adapter.TestRecyclerAdapter)

Example 9 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project XRecyclerView by jianghejie.

the class StaggeredGridActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recyclerview);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mRecyclerView = (XRecyclerView) this.findViewById(R.id.recyclerview);
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
    mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
    mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
    View header = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup) findViewById(android.R.id.content), false);
    mRecyclerView.addHeaderView(header);
    mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {

        @Override
        public void onRefresh() {
            refreshTime++;
            times = 0;
            new Handler().postDelayed(new Runnable() {

                public void run() {
                    listData.clear();
                    for (int i = 0; i < 25; i++) {
                        listData.add("item" + i + "after " + refreshTime + " times of refresh");
                    }
                    mAdapter.notifyDataSetChanged();
                    mRecyclerView.refreshComplete();
                }
            }, //refresh data here
            1000);
        }

        @Override
        public void onLoadMore() {
            if (times < 2) {
                new Handler().postDelayed(new Runnable() {

                    public void run() {
                        mRecyclerView.loadMoreComplete();
                        for (int i = 0; i < 25; i++) {
                            listData.add("item" + (i + listData.size()));
                        }
                        mRecyclerView.loadMoreComplete();
                        mAdapter.notifyDataSetChanged();
                    }
                }, 1000);
            } else {
                new Handler().postDelayed(new Runnable() {

                    public void run() {
                        for (int i = 0; i < 9; i++) {
                            listData.add("item" + (1 + listData.size()));
                        }
                        mRecyclerView.setNoMore(true);
                        mAdapter.notifyDataSetChanged();
                    }
                }, 1000);
            }
            times++;
        }
    });
    listData = new ArrayList<String>();
    for (int i = 0; i < 25; i++) {
        listData.add("item" + i);
    }
    mAdapter = new MyAdapter(listData);
    mRecyclerView.setAdapter(mAdapter);
}
Also used : XRecyclerView(com.jcodecraeer.xrecyclerview.XRecyclerView) Handler(android.os.Handler) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) XRecyclerView(com.jcodecraeer.xrecyclerview.XRecyclerView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 10 with StaggeredGridLayoutManager

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

the class RecyclerViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recyclerview);
    initDatas();
    mRecyclerView = (RecyclerView) findViewById(R.id.id_recyclerview);
    //        mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
    //        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
    mAdapter = new CommonAdapter<String>(this, R.layout.item_list, mDatas) {

        @Override
        protected void convert(ViewHolder holder, String s, int position) {
            holder.setText(R.id.id_item_list_title, s + " : " + holder.getAdapterPosition() + " , " + holder.getLayoutPosition());
        }
    };
    initHeaderAndFooter();
    //        initEmptyView();
    mLoadMoreWrapper = new LoadMoreWrapper(mHeaderAndFooterWrapper);
    mLoadMoreWrapper.setLoadMoreView(R.layout.default_loading);
    mLoadMoreWrapper.setOnLoadMoreListener(new LoadMoreWrapper.OnLoadMoreListener() {

        @Override
        public void onLoadMoreRequested() {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    for (int i = 0; i < 10; i++) {
                        mDatas.add("Add:" + i);
                    }
                    mLoadMoreWrapper.notifyDataSetChanged();
                }
            }, 3000);
        }
    });
    mRecyclerView.setAdapter(mLoadMoreWrapper);
    mAdapter.setOnItemClickListener(new CommonAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
            Toast.makeText(RecyclerViewActivity.this, "pos = " + position, Toast.LENGTH_SHORT).show();
            mAdapter.notifyItemRemoved(position);
        }

        @Override
        public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
            return false;
        }
    });
}
Also used : LoadMoreWrapper(com.zhy.adapter.recyclerview.wrapper.LoadMoreWrapper) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CommonAdapter(com.zhy.adapter.recyclerview.CommonAdapter) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) ViewHolder(com.zhy.adapter.recyclerview.base.ViewHolder) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)71 RecyclerView (android.support.v7.widget.RecyclerView)47 View (android.view.View)32 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)30 GridLayoutManager (android.support.v7.widget.GridLayoutManager)22 Handler (android.os.Handler)7 TextView (android.widget.TextView)7 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)6 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 Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 ArrayList (java.util.ArrayList)4 Bundle (android.os.Bundle)3 Nullable (android.support.annotation.Nullable)3 MenuItem (android.view.MenuItem)3 RefreshListenerAdapter (com.lcodecore.tkrefreshlayout.RefreshListenerAdapter)3