Search in sources :

Example 16 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project MaterialViewPager by florent37.

the class Utils method scrollTo.

public static void scrollTo(Object scroll, float yOffset) {
    if (scroll instanceof RecyclerView) {
        //RecyclerView.scrollTo : UnsupportedOperationException
        //Moved to the RecyclerView.LayoutManager.scrollToPositionWithOffset
        //Have to be instanceOf RecyclerView.LayoutManager to work (so work with RecyclerView.GridLayoutManager)
        final RecyclerView.LayoutManager layoutManager = ((RecyclerView) scroll).getLayoutManager();
        if (layoutManager instanceof LinearLayoutManager) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
            linearLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            staggeredGridLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        }
    } else if (scroll instanceof NestedScrollView) {
        ((NestedScrollView) scroll).scrollTo(0, (int) yOffset);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 17 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project material-sheet-fab by gowong.

the class NotesListFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(getLayoutResId(), container, false);
    // Setup list
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.notes_list);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(getNumColumns(), StaggeredGridLayoutManager.VERTICAL));
    recyclerView.setAdapter(new NotesAdapter(getActivity(), getNumItems()));
    return view;
}
Also used : NotesAdapter(com.gordonwong.materialsheetfab.sample.adapters.NotesAdapter) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Example 18 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project CloudReader by youlookwhat.

the class BookCustomFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    showContentView();
    bindingView.srlBook.setColorSchemeColors(CommonUtils.getColor(R.color.colorTheme));
    bindingView.srlBook.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            DebugUtil.error("-----onRefresh");
            //                listTag= Arrays.asList(BookApiUtils.getApiTag(position));
            //                String tag=BookApiUtils.getRandomTAG(listTag);
            //                doubanBookPresenter.searchBookByTag(BookReadingFragment.this,tag,false);
            bindingView.srlBook.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mStart = 0;
                    loadCustomData();
                }
            }, 1000);
        }
    });
    //        mBookAdapter = new BookAdapter(getActivity());
    //        mLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
    mLayoutManager = new GridLayoutManager(getActivity(), 3);
    bindingView.xrvBook.setLayoutManager(mLayoutManager);
    //        bindingView.xrvBook.setAdapter(mBookAdapter);
    scrollRecycleView();
    // 准备就绪
    mIsPrepared = true;
    /**
         * 因为启动时先走loadData()再走onActivityCreated,
         * 所以此处要额外调用load(),不然最初不会加载内容
         */
    loadData();
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 19 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project CloudReader by youlookwhat.

the class WelfareFragment method setAdapter.

private void setAdapter(GankIoDataBean gankIoDataBean) {
    //        mWelfareAdapter = new WelfareAdapter();
    mWelfareAdapter.addAll(gankIoDataBean.getResults());
    //构造器中,第一个参数表示列数或者行数,第二个参数表示滑动方向,瀑布流
    bindingView.xrvWelfare.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    bindingView.xrvWelfare.setAdapter(mWelfareAdapter);
    mWelfareAdapter.notifyDataSetChanged();
    mWelfareAdapter.setOnItemClickListener(new OnItemClickListener<GankIoDataBean.ResultBean>() {

        @Override
        public void onClick(GankIoDataBean.ResultBean resultsBean, int position) {
            DebugUtil.error("-----" + imgList.toString());
            DebugUtil.error("----imgList.size():  " + imgList.size());
            Bundle bundle = new Bundle();
            // 2,大图显示当前页数,1,头像,不显示页数
            bundle.putInt("selet", 2);
            //第几张
            bundle.putInt("code", position);
            bundle.putStringArrayList("imageuri", imgList);
            Intent intent = new Intent(getContext(), ViewBigImageActivity.class);
            intent.putExtras(bundle);
            getContext().startActivity(intent);
        }
    });
    // 显示成功后就不是第一次了,不再刷新
    isFirst = false;
}
Also used : GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) Bundle(android.os.Bundle) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) Intent(android.content.Intent) ViewBigImageActivity(com.example.jingbin.cloudreader.view.viewbigimage.ViewBigImageActivity)

Example 20 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project SwipeRecyclerView by yanzhenjie.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, LinearLayoutManager.VERTICAL));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.set(10, 10, 10, 15);
        }
    });
    List<String> titles = Arrays.asList(getResources().getStringArray(R.array.main_item));
    List<String> descriptions = Arrays.asList(getResources().getStringArray(R.array.main_item_des));
    MainItemAdapter mainItemAdapter = new MainItemAdapter(titles, descriptions);
    mainItemAdapter.setOnItemClickListener(this);
    recyclerView.setAdapter(mainItemAdapter);
}
Also used : Rect(android.graphics.Rect) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) MainItemAdapter(com.yanzhenjie.swiperecyclerview.adapter.MainItemAdapter) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)71 RecyclerView (android.support.v7.widget.RecyclerView)47 View (android.view.View)32 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)30 GridLayoutManager (android.support.v7.widget.GridLayoutManager)22 Handler (android.os.Handler)7 TextView (android.widget.TextView)7 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)6 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)5 ViewGroup (android.view.ViewGroup)5 AbsListView (android.widget.AbsListView)5 ScrollView (android.widget.ScrollView)5 BindView (butterknife.BindView)5 Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 ArrayList (java.util.ArrayList)4 Bundle (android.os.Bundle)3 Nullable (android.support.annotation.Nullable)3 MenuItem (android.view.MenuItem)3 RefreshListenerAdapter (com.lcodecore.tkrefreshlayout.RefreshListenerAdapter)3