Search in sources :

Example 1 with AdvanceDecoration

use of com.chinaztt.fda.widget.AdvanceDecoration 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 2 with AdvanceDecoration

use of com.chinaztt.fda.widget.AdvanceDecoration in project FastDev4Android by jiangqqlmj.

the class RecyclerRefreshActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recycler_refresh_layout);
    top_bar_linear_back = (LinearLayout) this.findViewById(R.id.top_bar_linear_back);
    top_bar_linear_back.setOnClickListener(new CustomOnClickListener());
    top_bar_title = (TextView) this.findViewById(R.id.top_bar_title);
    top_bar_title.setText("RecyclerView下拉刷新,下拉加载更多...");
    demo_swiperefreshlayout = (SwipeRefreshLayout) this.findViewById(R.id.demo_swiperefreshlayout);
    demo_recycler = (RecyclerView) this.findViewById(R.id.demo_recycler);
    // 设置刷新时动画的颜色,可以设置4个
    demo_swiperefreshlayout.setProgressBackgroundColorSchemeResource(android.R.color.white);
    demo_swiperefreshlayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
    demo_swiperefreshlayout.setProgressViewOffset(false, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));
    linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(OrientationHelper.VERTICAL);
    demo_recycler.setLayoutManager(linearLayoutManager);
    // 添加分隔线
    demo_recycler.addItemDecoration(new AdvanceDecoration(this, OrientationHelper.VERTICAL));
    demo_recycler.setAdapter(adapter = new RefreshRecyclerAdapter(this));
    demo_swiperefreshlayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            Log.d("zttjiangqq", "invoke onRefresh...");
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<String> newDatas = new ArrayList<String>();
                    for (int i = 0; i < 5; i++) {
                        int index = i + 1;
                        newDatas.add("new item" + index);
                    }
                    adapter.addItem(newDatas);
                    demo_swiperefreshlayout.setRefreshing(false);
                    Toast.makeText(RecyclerRefreshActivity.this, "更新了五条数据...", Toast.LENGTH_SHORT).show();
                }
            }, 1500);
        }
    });
    // RecyclerView滑动监听
    demo_recycler.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItem + 1 == adapter.getItemCount()) {
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        List<String> newDatas = new ArrayList<String>();
                        for (int i = 0; i < 5; i++) {
                            int index = i + 1;
                            newDatas.add("more item" + index);
                        }
                        adapter.addMoreItem(newDatas);
                    }
                }, 1000);
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AdvanceDecoration(com.chinaztt.fda.widget.AdvanceDecoration) RecyclerView(android.support.v7.widget.RecyclerView) RefreshRecyclerAdapter(com.chinaztt.fda.adapter.RefreshRecyclerAdapter)

Example 3 with AdvanceDecoration

use of com.chinaztt.fda.widget.AdvanceDecoration in project FastDev4Android by jiangqqlmj.

the class RecyclerFootActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recycler_footview_layout);
    top_bar_linear_back = (LinearLayout) this.findViewById(R.id.top_bar_linear_back);
    top_bar_linear_back.setOnClickListener(new CustomOnClickListener());
    top_bar_title = (TextView) this.findViewById(R.id.top_bar_title);
    top_bar_title.setText("RecyclerView使用FootView进行上拉加载更多...");
    demo_swiperefreshlayout = (SwipeRefreshLayout) this.findViewById(R.id.demo_swiperefreshlayout);
    demo_recycler = (RecyclerView) this.findViewById(R.id.demo_recycler);
    // 设置刷新时动画的颜色,可以设置4个
    demo_swiperefreshlayout.setProgressBackgroundColorSchemeResource(android.R.color.white);
    demo_swiperefreshlayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
    demo_swiperefreshlayout.setProgressViewOffset(false, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));
    linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(OrientationHelper.VERTICAL);
    demo_recycler.setLayoutManager(linearLayoutManager);
    // 添加分隔线
    demo_recycler.addItemDecoration(new AdvanceDecoration(this, OrientationHelper.VERTICAL));
    demo_recycler.setAdapter(adapter = new RefreshFootAdapter(this));
    demo_swiperefreshlayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            Log.d("zttjiangqq", "invoke onRefresh...");
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<String> newDatas = new ArrayList<String>();
                    for (int i = 0; i < 5; i++) {
                        int index = i + 1;
                        newDatas.add("new item" + index);
                    }
                    adapter.addItem(newDatas);
                    demo_swiperefreshlayout.setRefreshing(false);
                    Toast.makeText(RecyclerFootActivity.this, "更新了五条数据...", Toast.LENGTH_SHORT).show();
                }
            }, 5000);
        }
    });
    // RecyclerView滑动监听
    demo_recycler.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItem + 1 == adapter.getItemCount()) {
                adapter.changeMoreStatus(RefreshFootAdapter.LOADING_MORE);
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        List<String> newDatas = new ArrayList<String>();
                        for (int i = 0; i < 5; i++) {
                            int index = i + 1;
                            newDatas.add("more item" + index);
                        }
                        adapter.addMoreItem(newDatas);
                        adapter.changeMoreStatus(RefreshFootAdapter.PULLUP_LOAD_MORE);
                    }
                }, 2500);
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AdvanceDecoration(com.chinaztt.fda.widget.AdvanceDecoration) RefreshFootAdapter(com.chinaztt.fda.adapter.RefreshFootAdapter) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 RecyclerView (android.support.v7.widget.RecyclerView)3 AdvanceDecoration (com.chinaztt.fda.widget.AdvanceDecoration)3 Handler (android.os.Handler)2 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)2 ArrayList (java.util.ArrayList)2 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 View (android.view.View)1 TextView (android.widget.TextView)1 RefreshFootAdapter (com.chinaztt.fda.adapter.RefreshFootAdapter)1 RefreshRecyclerAdapter (com.chinaztt.fda.adapter.RefreshRecyclerAdapter)1 TestRecyclerAdapter (com.chinaztt.fda.adapter.TestRecyclerAdapter)1