use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project CloudReader by youlookwhat.
the class FilmComingFragment method initRefreshView.
private void initRefreshView() {
bindingView.srlWan.setColorSchemeColors(CommonUtils.getColor(activity, R.color.colorTheme));
adapter = new FilmComingAdapter(activity);
bindingView.xrvWan.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
bindingView.xrvWan.setItemAnimator(null);
bindingView.xrvWan.setHasFixedSize(true);
bindingView.xrvWan.setLoadMoreEnabled(true);
viewModel.bookType.set(mType);
bindingView.xrvWan.setAdapter(adapter);
bindingView.xrvWan.setOnItemClickListener(new OnItemFilterClickListener() {
@Override
public void onSingleClick(View v, int position) {
ImageView imageView = v.findViewById(R.id.iv_top_photo);
ComingFilmBean.MoviecomingsBean bean = adapter.getItemData(position);
FilmItemBean filmItemBean = new FilmItemBean();
filmItemBean.setId(bean.getId());
filmItemBean.setDN(bean.getDirector());
filmItemBean.setTCn(bean.getTitle());
filmItemBean.setTEn(bean.getReleaseDate());
filmItemBean.setMovieType(bean.getType());
filmItemBean.setImg(bean.getImage());
filmItemBean.setLocationName(bean.getLocationName());
String actor1 = bean.getActor1();
String actor2 = bean.getActor2();
if (!TextUtils.isEmpty(actor2)) {
actor1 = actor1 + " / " + actor2;
}
filmItemBean.setActors(actor1);
FilmDetailActivity.start(activity, filmItemBean, imageView);
}
});
bindingView.srlWan.setOnRefreshListener(this::getHotFilm);
}
use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project CloudReader by youlookwhat.
the class RefreshHelper method initStaggeredGrid.
public static void initStaggeredGrid(ByRecyclerView recyclerView, int spanCount, int spacing) {
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL));
// 如果每个item高度一致设置后效率更高
recyclerView.setHasFixedSize(true);
// recyclerView.setItemAnimator(null);
recyclerView.addItemDecoration(new GridSpaceItemDecoration(spacing));
recyclerView.setRefreshHeaderView(new NeteaseRefreshHeaderView(recyclerView.getContext()));
recyclerView.setLoadingMoreView(new NeteaseLoadMoreView(recyclerView.getContext()));
}
use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project Douya by DreaminginCodeZH.
the class ProfileFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
CustomTabsHelperFragment.attachTo(this);
mResource = ProfileResource.attachTo(mUserIdOrUid, mSimpleUser, mUser, this);
mScrollLayout.setListener(new ProfileLayout.Listener() {
@Override
public void onEnterAnimationEnd() {
}
@Override
public void onExitAnimationEnd() {
getActivity().finish();
}
});
if (savedInstanceState == null) {
mScrollLayout.enter();
}
mDismissView.setOnClickListener(view -> exit());
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(mToolbar);
activity.getSupportActionBar().setTitle(null);
if (mResource.hasUser()) {
mHeaderLayout.bindUser(mResource.getUser());
} else if (mResource.hasSimpleUser()) {
mHeaderLayout.bindSimpleUser(mResource.getSimpleUser());
}
mHeaderLayout.setListener(this);
mToolbar.setOnDoubleClickListener(view -> {
if (!mScrollLayout.isHeaderCollapsed()) {
return false;
}
mScrollLayout.animateHeaderViewScroll(false);
return true;
});
if (ViewUtils.hasSw600Dp(activity)) {
mContentList.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
} else {
mContentList.setLayoutManager(new LinearLayoutManager(activity));
}
mAdapter = new ProfileAdapter(this);
mContentList.setAdapter(mAdapter);
mContentStateLayout.setLoading();
if (mResource.isAnyLoaded()) {
mResource.notifyChangedIfLoaded();
}
}
use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project SwipeRecyclerView by yanzhenjie.
the class StaggeredActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scroll);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
mRecyclerView = findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
mRecyclerView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(View itemView, int position) {
// 根据原position判断该item是否是parent item
if (mAdapter.isParentItem(position)) {
// 换取parent position
int parentPosition = mAdapter.parentItemPosition(position);
// 判断parent是否打开了二级菜单
if (mAdapter.isExpanded(parentPosition)) {
mDataList.get(parentPosition).setExpanded(false);
mAdapter.notifyParentChanged(parentPosition);
// 关闭该parent下的二级菜单
mAdapter.collapseParent(parentPosition);
} else {
mDataList.get(parentPosition).setExpanded(true);
mAdapter.notifyParentChanged(parentPosition);
// 打开该parent下的二级菜单
mAdapter.expandParent(parentPosition);
}
} else {
// 换取parent position
int parentPosition = mAdapter.parentItemPosition(position);
// 换取child position
int childPosition = mAdapter.childItemPosition(position);
String message = String.format("我是%1$d爸爸的%2$d儿子", parentPosition, childPosition);
Toast.makeText(StaggeredActivity.this, message, Toast.LENGTH_LONG).show();
}
}
});
mAdapter = new ExpandedAdapter(this);
mRecyclerView.setAdapter(mAdapter);
refresh();
}
use of androidx.recyclerview.widget.StaggeredGridLayoutManager in project SwipeRecyclerView by yanzhenjie.
the class DefaultItemDecoration method onDraw.
@Override
public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
assert layoutManager != null;
int orientation = getOrientation(layoutManager);
int spanCount = getSpanCount(layoutManager);
int childCount = layoutManager.getChildCount();
if (layoutManager instanceof LinearLayoutManager) {
canvas.save();
for (int i = 0; i < childCount; i++) {
View view = layoutManager.getChildAt(i);
assert view != null;
int position = parent.getChildLayoutPosition(view);
if (orientation == RecyclerView.VERTICAL) {
drawVertical(canvas, view, position, spanCount, childCount);
} else {
drawHorizontal(canvas, view, position, spanCount, childCount);
}
}
canvas.restore();
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
canvas.save();
for (int i = 0; i < childCount; i++) {
View view = layoutManager.getChildAt(i);
mDrawer.drawLeft(view, canvas);
mDrawer.drawTop(view, canvas);
mDrawer.drawRight(view, canvas);
mDrawer.drawBottom(view, canvas);
}
canvas.restore();
}
}
Aggregations