Search in sources :

Example 1 with StaggeredGridLayoutManager

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);
}
Also used : OnItemFilterClickListener(me.jingbin.library.view.OnItemFilterClickListener) FilmItemBean(com.example.jingbin.cloudreader.bean.moviechild.FilmItemBean) FilmComingAdapter(com.example.jingbin.cloudreader.adapter.FilmComingAdapter) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View)

Example 2 with StaggeredGridLayoutManager

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()));
}
Also used : NeteaseRefreshHeaderView(com.example.jingbin.cloudreader.view.byview.NeteaseRefreshHeaderView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) NeteaseLoadMoreView(com.example.jingbin.cloudreader.view.byview.NeteaseLoadMoreView) GridSpaceItemDecoration(me.jingbin.library.decoration.GridSpaceItemDecoration)

Example 3 with StaggeredGridLayoutManager

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();
    }
}
Also used : AppCompatActivity(androidx.appcompat.app.AppCompatActivity) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 4 with StaggeredGridLayoutManager

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();
}
Also used : DefaultItemDecoration(com.yanzhenjie.recyclerview.widget.DefaultItemDecoration) OnItemClickListener(com.yanzhenjie.recyclerview.OnItemClickListener) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) ExpandedAdapter(com.yanzhenjie.recyclerview.sample.adapter.ExpandedAdapter) SwipeRecyclerView(com.yanzhenjie.recyclerview.SwipeRecyclerView) View(android.view.View) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 5 with StaggeredGridLayoutManager

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();
    }
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)34 RecyclerView (androidx.recyclerview.widget.RecyclerView)23 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)15 View (android.view.View)13 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)9 Toolbar (androidx.appcompat.widget.Toolbar)6 AbsListView (android.widget.AbsListView)5 WebView (android.webkit.WebView)3 ScrollView (android.widget.ScrollView)3 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)3 BindView (butterknife.BindView)3 OnItemLongClickListener (xyz.zpayh.adapter.OnItemLongClickListener)3 DialogInterface (android.content.DialogInterface)2 Adapter (android.widget.Adapter)2 ItemTouchHelper (androidx.recyclerview.widget.ItemTouchHelper)2 SimpleItemAnimator (androidx.recyclerview.widget.SimpleItemAnimator)2 ScrollableLayoutItem (eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem)2 FavLessonFragmentView (pri.weiqiang.liyujapanese.mvp.view.dic.FavLessonFragmentView)2 StaggeredGridAdapter (pri.weiqiang.liyujapanese.ui.adapter.StaggeredGridAdapter)2 OnItemClickLitener (pri.weiqiang.liyujapanese.ui.adapter.stagger.OnItemClickLitener)2