use of com.seven.seven.home.adapter.HomeCommonAdapter in project seven_develop by seven123456.
the class HomeFragment method initRecyclerView.
/*
* 初始化recycler并且初始化headview添加到recycler里面
* */
private void initRecyclerView() {
recyclerView.setLayoutManager(linearLayoutManager);
homeCommonAdapter = new HomeCommonAdapter(R.layout.recycler_item_home_news, newsInfosList, getContext());
initHeadView();
homeCommonAdapter.setOnLoadMoreListener(this, recyclerView);
homeCommonAdapter.disableLoadMoreIfNotFullPage();
homeCommonAdapter.addHeaderView(headView);
recyclerView.setAdapter(homeCommonAdapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
// Drawable drawable = getContext().getResources().getDrawable(R.drawable.home_toolbar_bg);
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
// if (isFirst) {
// int toolbarHeight = appBarLayout.getMeasuredHeight();
int toolbarHeight = getResources().getDimensionPixelSize(R.dimen.main_title_bar_height);
int scollyHeight = recyclerView.computeVerticalScrollOffset();
if (scollyHeight >= (toolbarHeight * 2)) {
/*此时toolbar和状态栏完全显示红色*/
// appBarLayout.setVisibility(View.VISIBLE);
// drawable.setAlpha(255);
// appBarLayout.setBackground(drawable);
homeTitleBar.setBgAlpha(1);
} else if (scollyHeight >= toolbarHeight) {
/*
* 渐变过程
* */
// appBarLayout.setVisibility(View.VISIBLE);
// drawable.setAlpha((int) (255 * ((scollyHeight - toolbarHeight) / (toolbarHeight * 1.5F))));
// appBarLayout.setBackground(drawable);
homeTitleBar.setBgAlpha((scollyHeight - toolbarHeight) / (toolbarHeight * 2F));
} else {
/*
* 状态栏透明
* */
// appBarLayout.setVisibility(View.GONE);
homeTitleBar.setBgAlpha(0);
}
// } else {
// isFirst = true;
// }
super.onScrolled(recyclerView, dx, dy);
}
});
homeCommonAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
HomeNewsInfos.NewsInfos newsInfos = (HomeNewsInfos.NewsInfos) adapter.getItem(position);
HomeToWebViewInfo homeToWebViewInfo = new HomeToWebViewInfo();
homeToWebViewInfo.h5Url = newsInfos.getLink();
homeToWebViewInfo.imgUrl = newsInfos.getEnvelopePic();
homeToWebViewInfo.title = newsInfos.getTitle();
homeToWebViewInfo.id = newsInfos.getId();
homeToWebViewInfo.collect = newsInfos.isCollect();
Intent intent = new Intent(getContext(), HomeNewsDetailActivity.class);
intent.putExtra("newsInfo", homeToWebViewInfo);
/*
* item 里面的img设置一个属性,相对应页面的img里面也必须设置
* getResources().getString(R.string.transition_news_img)
* */
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) getContext(), view.findViewById(R.id.iv_right), getResources().getString(R.string.transition_news_img));
ActivityCompat.startActivity(getContext(), intent, options.toBundle());
}
});
}
Aggregations