private void getDataView() { float imgWidths = DPIUtil.screen_width; float imgHeight = imgWidths * 284 / 716; ViewGroup.LayoutParams params = viewPager.getLayoutParams(); params.height = Math.round(imgHeight); params.width = Math.round(imgWidths); viewPager.setLayoutParams(params); custemViewPagerAdapter = new CustemViewPagerAdapter(mViewList); viewPager.setAdapter(custemViewPagerAdapter); mRecyclerView.addHeaderView(headView); adapter = new GridViewAdapter(getActivity(), mList, imgWidth); mRecyclerView.setAdapter(adapter); setListener(); initPopupWindow(); getHomeData(); }
private void setListener() { adapter.setOnItemClickListener( new RecyclerViewItemClickListener() { @Override public void onItemClick(View view, int position) { if (SharedPreferenceUtil.getSharedPreference(getActivity()) .getString(SharedPreferenceUtil.MOD1, "0") .equals("0")) { ((MainActivity) getActivity()).showMod1(); } else { showPopWindow(position - 1); worksEntry = mList.get(position - 1); clickItemIndex = position - 1; } } }); // 上拉加载 mRecyclerView.setOnScrollListener( new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { switch (newState) { case RecyclerView.SCROLL_STATE_IDLE: break; } super.onScrollStateChanged(recyclerView, newState); } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); firstVisibleItem = layoutManager.findFirstVisibleItemPositions(firstVisiableItemPositions)[0]; visibleItemCount = mRecyclerView.getChildCount(); totalItemCount = layoutManager.getItemCount(); if (loading) { if (totalItemCount > previousTotal) { loading = false; previousTotal = totalItemCount; } } if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem)) { // End has been reached progressBar_bottom.setVisibility(View.VISIBLE); getListData(); // Do something loading = true; } } }); }
private void initView(LayoutInflater inflater) { layView = inflater.inflate(R.layout.fragment_main, null); mRecyclerView = (CustomRecyclerView) layView.findViewById(R.id.main_recycler_view); // layoutManager = new StaggeredGridLayoutManager(2, // StaggeredGridLayoutManager.VERTICAL); layoutManager = new CustomStaggeredGridLayoutManager(2, CustomStaggeredGridLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(layoutManager); refreshLayout = (SwipeRefreshLayout) layView.findViewById(R.id.swipe_container); progressBar_bottom = (ProgressBarIndeterminate) layView.findViewById(R.id.main_progressBar_bottom); headView = inflater.inflate(R.layout.recycler_headview, null); viewPager = (ViewPager) headView.findViewById(R.id.activity_main_custemviewpager); pointLayout = (LinearLayout) headView.findViewById(R.id.mainpager_pointcontainer); circleBar = CircleDialogProgressBar.createCircleDialogProgressBar(getActivity()); circleBar.show(); }