Java Code Examples for android.support.v7.widget.RecyclerView#setOnScrollListener()

The following examples show how to use android.support.v7.widget.RecyclerView#setOnScrollListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParallaxRecyclerAdapter.java    From Bailan with Apache License 2.0 6 votes vote down vote up
/**
 * Set the view as header.
 *
 * @param header The inflated header
 * @param view   The RecyclerView to set scroll listeners
 */
public void setParallaxHeader(View header, final RecyclerView view) {
    mRecyclerView = view;
    mHeader = new CustomRelativeWrapper(header.getContext(), mShouldClipView);
    mHeader.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mHeader.addView(header, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    view.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (mHeader != null) {
                translateHeader(mRecyclerView.getLayoutManager().getChildAt(0) == mHeader ?
                        mRecyclerView.computeVerticalScrollOffset() : mHeader.getHeight());

            }
        }
    });
}
 
Example 2
Source File: RxImageListFragment.java    From jus with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v =  inflater.inflate(R.layout.fragment_imagelist, container, false);
    // Inflate the layout for this fragment
    ListScrollListener listScrollListener = new ListScrollListener();
    RecyclerAdapter recyclerAdapter =  new RecyclerAdapter(
            MockData.getMockJsonArray(500, 500)
            //MockData.getAssetsMock(getActivity())
            , getActivity(), listScrollListener);
    RecyclerView recyclerView = (RecyclerView) v.findViewById(R.id.list_images);
    recyclerView.setOnScrollListener(listScrollListener);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setAdapter(recyclerAdapter);

   return v;
}
 
Example 3
Source File: TangramEngine.java    From Tangram-Android with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void bindView(@NonNull RecyclerView view) {
    super.bindView(view);

    mSwipeItemTouchListener = new SwipeItemTouchListener(view.getContext(), mGroupBasicAdapter, getContentView());
    if (mSwipeCardActionEdge != -1) {
        mSwipeItemTouchListener.setActionEdge(mSwipeCardActionEdge);
    }

    view.addOnItemTouchListener(mSwipeItemTouchListener);
    view.setOnScrollListener(new RecyclerView.OnScrollListener(){
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (recyclerView != null) {
                scrolledY += dy;
            }
        }
    });
}
 
Example 4
Source File: ParallaxRecyclerAdapter.java    From android-parallax-recyclerview with Apache License 2.0 6 votes vote down vote up
/**
 * Set the view as header.
 *
 * @param header The inflated header
 * @param view   The RecyclerView to set scroll listeners
 */
public void setParallaxHeader(View header, final RecyclerView view) {
    mRecyclerView = view;
    mHeader = new CustomRelativeWrapper(header.getContext(), mShouldClipView);
    mHeader.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mHeader.addView(header, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    view.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (mHeader != null) {
                translateHeader(mRecyclerView.getLayoutManager().getChildAt(0) == mHeader ?
                        mRecyclerView.computeVerticalScrollOffset() : mHeader.getHeight());

            }
        }
    });
}
 
Example 5
Source File: TangramEngine.java    From Tangram-Android with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void bindView(@NonNull RecyclerView view) {
    super.bindView(view);

    mSwipeItemTouchListener = new SwipeItemTouchListener(view.getContext(), mGroupBasicAdapter, getContentView());
    if (mSwipeCardActionEdge != -1) {
        mSwipeItemTouchListener.setActionEdge(mSwipeCardActionEdge);
    }

    view.addOnItemTouchListener(mSwipeItemTouchListener);
    view.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (recyclerView != null) {
                scrolledY += dy;
            }
        }
    });
}
 
Example 6
Source File: ParallaxRecyclerAdapter.java    From Bailan with Apache License 2.0 6 votes vote down vote up
/**
 * Set the view as header.
 *
 * @param header The inflated header
 * @param view   The RecyclerView to set scroll listeners
 */
public void setParallaxHeader(View header, final RecyclerView view) {
    mRecyclerView = view;
    mHeader = new CustomRelativeWrapper(header.getContext(), mShouldClipView);
    mHeader.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mHeader.addView(header, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    view.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (mHeader != null) {
                translateHeader(mRecyclerView.getLayoutManager().getChildAt(0) == mHeader ?
                        mRecyclerView.computeVerticalScrollOffset() : mHeader.getHeight());

            }
        }
    });
}
 
Example 7
Source File: MainActivity.java    From Moticons with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.context = this;
    this.appPreferences = MoticonsApplication.getAppPreferences();

    initUI();
    isFirstRun();

    recyclerView = (RecyclerView) findViewById(R.id.moticonList);
    fastScroller = (VerticalRecyclerViewFastScroller) findViewById(R.id.fast_scroller);
    progressWheel = (ProgressWheel) findViewById(R.id.progress);
    noResults = (LinearLayout) findViewById(R.id.noResults);

    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(linearLayoutManager);

    fastScroller.setRecyclerView(recyclerView);
    recyclerView.setOnScrollListener(fastScroller.getOnScrollListener());
    progressWheel.setVisibility(View.VISIBLE);

    new getMoticons().execute();
}
 
Example 8
Source File: SuntimesActivity.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
/**
 * initialize the card flipper and associated views
 * @param context a context used to access resources
 */
private void initCardViews(Context context)
{
    card_adapter = new CardAdapter(context);
    card_adapter.setCardAdapterListener(cardAdapterListener);

    card_view = (RecyclerView) findViewById(R.id.info_time_flipper1);
    card_view.setHasFixedSize(true);
    card_view.setItemViewCacheSize(7);
    card_view.setLayoutManager(card_layout = new CardLayoutManager(this));
    card_view.addItemDecoration(new CardAdapter.CardViewDecorator(this));

    card_view.setAdapter(card_adapter);
    card_view.scrollToPosition(CardAdapter.TODAY_POSITION);

    SnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(card_view);
    card_scroller = new CardAdapter.CardViewScroller(context);
    card_view.setOnScrollListener(onCardScrollListener);
}
 
Example 9
Source File: RecyclerViewScrollActivity.java    From AndroidDemo with MIT License 5 votes vote down vote up
@Override
protected void init() {
    viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);
    et_position = (EditText) findViewById(R.id.et_position);
    rg_tab = (RadioGroup) findViewById(R.id.rg_tab);

    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);

    linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    gridLayoutManager = new GridLayoutManager(this, 4);
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            return position % 5 == 0 ? 4 : 1;
        }
    });

    recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    recyclerView.setLayoutManager(linearLayoutManager);
    SimpleRecyclerAdapter simpleRecyclerAdapter = new SimpleRecyclerAdapter(this, data);
    recyclerView.setAdapter(simpleRecyclerAdapter);
    recyclerView.setOnScrollListener(onScrollListener);

    imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    for (int i = 0; i < 100; i++) {
        data.add("Simple item " + i);
    }
    simpleRecyclerAdapter.notifyDataSetChanged();

    initTab();
}
 
Example 10
Source File: RecylerActivity.java    From android-Stupid-Adapter with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_recyler);
	recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
	// 创建一个线性布局管理器
	LinearLayoutManager layoutManager = new LinearLayoutManager(this);
	layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
	// 设置布局管理器
	recyclerView.setLayoutManager(layoutManager);
	adapter = new XRecylerAdapter<Vlist>(VlistViewHolder.class, null);
	recyclerView.setAdapter(adapter);
	recyclerView.setOnScrollListener(adapter.getOnScrollListener(null));
	getHttp().get(50, "http://cache.video.iqiyi.com/jp/avlist/202861101/",
			this);

	try {
		String str = "<RequestData><HeadData><UserCode>sh1_admin</UserCode><UserName>sh1_admin</UserName><UserCompanyCode>3107</UserCompanyCode><UserCompanyName>上海分公司一部</UserCompanyName><RequestType>03</RequestType></HeadData><BodyData><ReportId>113100000033</ReportId><Insurant>a5rfg87</Insurant><NumberPlate>沪E78612</NumberPlate><EngineModel></EngineModel><CarVin></CarVin><AccidentDate>2011-02-25 15:07:00</AccidentDate><ReportDate>2011-02-25 15:07:00</ReportDate><Province>310000</Province><City>310100</City><District></District><AccidentPlace>1</AccidentPlace><AccidentLongitude></AccidentLongitude><AccidentLatitude></AccidentLatitude><SurveyLongitude></SurveyLongitude><SurveyLatitude></SurveyLatitude><SceneReportFlag></SceneReportFlag><Reporter></Reporter><ReporterTel></ReporterTel><SurveyPlace></SurveyPlace><OperatorId>3525</OperatorId><OperatorName>sh_admin</OperatorName><ReportDealId>30000800</ReportDealId><ReportDealName>江苏分公司</ReportDealName><CompanyName></CompanyName><CustomerTypeCode></CustomerTypeCode><ForcePolicyId>a5rfg87a5rfg87a5rfg87</ForcePolicyId><BizPolicyId></BizPolicyId><Index>0</Index><FieldName>5</FieldName></BodyData></RequestData>";

		XmlDom dom = new XmlDom(str);
		dom.tag("UserCode").text();

	} catch (SAXException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example 11
Source File: MainActivity.java    From Rocko-Android-Demos with Apache License 2.0 5 votes vote down vote up
private void init() {
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    setTitle(R.string.app_name);
    mToolbar.setTitleTextColor(Color.WHITE);

    mFabButton = (ImageButton) findViewById(R.id.fab);
    mFabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "FAB", Toast.LENGTH_SHORT).show();
        }
    });

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    RecyclerAdapter recyclerAdapter = new RecyclerAdapter(createItemList());
    recyclerView.setAdapter(recyclerAdapter);
    recyclerView.setOnScrollListener(new HidingScrollListener() {
        @Override
        public void onHide() {
            hideViews();
        }

        @Override
        public void onShow() {
            showViews();
        }
    });

}
 
Example 12
Source File: FloatingActionButton.java    From LLApp with Apache License 2.0 5 votes vote down vote up
public void attachToRecyclerView(@NonNull RecyclerView recyclerView,
                                 ScrollDirectionListener scrollDirectionlistener,
                                 RecyclerView.OnScrollListener onScrollListener) {
    RecyclerViewScrollDetectorImpl scrollDetector = new RecyclerViewScrollDetectorImpl();
    scrollDetector.setScrollDirectionListener(scrollDirectionlistener);
    scrollDetector.setOnScrollListener(onScrollListener);
    scrollDetector.setScrollThreshold(mScrollThreshold);
    recyclerView.setOnScrollListener(scrollDetector);
}
 
Example 13
Source File: FloatActionButtonScrollDetectorHelper.java    From talk-android with MIT License 5 votes vote down vote up
public void attachToRecyclerView(@NonNull RecyclerView recyclerView,
                                 ScrollDirectionListener scrollDirectionlistener,
                                 RecyclerView.OnScrollListener onScrollListener) {
    RecyclerViewScrollDetectorImpl scrollDetector = new RecyclerViewScrollDetectorImpl();
    scrollDetector.setScrollDirectionListener(scrollDirectionlistener);
    scrollDetector.setOnScrollListener(onScrollListener);
    scrollDetector.setScrollThreshold(DensityUtil.dip2px(MainApp.CONTEXT, 4));
    recyclerView.setOnScrollListener(scrollDetector);
}
 
Example 14
Source File: PageDetectorSupport.java    From Tangram-Android with MIT License 5 votes vote down vote up
public void startDetectFastScroll() {
    if (mOnScrollListener != null) {
        RecyclerView recyclerView = mTangramEngine.getContentView();
        if (recyclerView != null) {
            recyclerView.removeOnScrollListener(mOnScrollListener);
            recyclerView.setOnScrollListener(mOnScrollListener);
        }
    }
}
 
Example 15
Source File: BindingConfig.java    From Android-MVVMFramework with Apache License 2.0 4 votes vote down vote up
@BindingAdapter({"addOnScrollListener"})
public static void addOnScrollListener(RecyclerView view, RecyclerView.OnScrollListener listener) {
    if(listener!=null)
        view.setOnScrollListener(listener);
}
 
Example 16
Source File: RecyclerRefreshLayout.java    From umeng_community_android with MIT License 4 votes vote down vote up
public RecyclerView findRefreshViewById(int id) {
    mRecyclerView = (RecyclerView) this.findViewById(id);
    mRecyclerView.setOnScrollListener(mScrollListener);
    return mRecyclerView;
}
 
Example 17
Source File: ModLog.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);

    RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(getActivity());
    rv.setLayoutManager(mLayoutManager);

    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);

    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("mod", getActivity()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new ModLogPosts();
    adapter = new ModLogAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);

    rv.setOnScrollListener(new ToolbarScrollHideHandler(((ModQueue) getActivity()).mToolbar, (getActivity()).findViewById(R.id.header)));

    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    posts.loadMore(adapter);
                }
            }
    );
    return v;
}
 
Example 18
Source File: MainActivity.java    From DragSortRecycler with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {

    final String TAG = "MainActivity";

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);

    final ArrayList<Integer> items = new ArrayList<>();

    for (int n=0;n<100;n++)
    {
        items.add(n);
    }

    final CustomAdapter adapter = new CustomAdapter(items,this);
  //  adapter.setHasStableIds(true);

    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager( new LinearLayoutManager(this));
    recyclerView.setItemAnimator(null);

    DragSortRecycler dragSortRecycler = new DragSortRecycler();
    dragSortRecycler.setViewHandleId(R.id.imageView);
    dragSortRecycler.setFloatingAlpha(0.4f);
    dragSortRecycler.setFloatingBgColor(0x800000FF);
    dragSortRecycler.setAutoScrollSpeed(0.3f);
    dragSortRecycler.setAutoScrollWindow(0.1f);

    dragSortRecycler.setOnItemMovedListener(new DragSortRecycler.OnItemMovedListener() {
        @Override
        public void onItemMoved(int from, int to) {
            Log.d(TAG, "onItemMoved " + from + " to " + to);
            Integer item = items.remove(from);
            items.add(to, item);
            adapter.notifyDataSetChanged();
            //notifyItemMoved does work, but it makes the list scroll pos jump a little when dragging near the top or bottom
            //adapter.notifyItemMoved(from,to);
        }
    });

    dragSortRecycler.setOnDragStateChangedListener(new DragSortRecycler.OnDragStateChangedListener() {
        @Override
        public void onDragStart() {
            Log.d(TAG, "Drag Start");
        }

        @Override
        public void onDragStop() {
            Log.d(TAG, "Drag Stop");
        }
    });

    recyclerView.addItemDecoration(dragSortRecycler);
    recyclerView.addOnItemTouchListener(dragSortRecycler);
    recyclerView.setOnScrollListener(dragSortRecycler.getScrollListener());
}
 
Example 19
Source File: ModPage.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);

    RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(getActivity());
    rv.setLayoutManager(mLayoutManager);

    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);

    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getActivity()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new ModeratorPosts(id, sub);
    adapter = new ModeratorAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);

    rv.setOnScrollListener(new ToolbarScrollHideHandler(((ModQueue) getActivity()).mToolbar, (getActivity()).findViewById(R.id.header)));

    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    posts.loadMore(adapter, id, sub);
                }
            }
    );
    return v;
}
 
Example 20
Source File: AyahWordFragment.java    From Word-By-Word-Quran-Android with MIT License 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_ayah_word, container, false);

    mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_ayah_word_view);

    //for fast scroll
    VerticalRecyclerViewFastScroller fastScroller = (VerticalRecyclerViewFastScroller) view.findViewById(R.id.fast_scroller);

    // Connect the recycler to the scroller (to let the scroller scroll the list)
    fastScroller.setRecyclerView(mRecyclerView);

    // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
    mRecyclerView.setOnScrollListener(fastScroller.getOnScrollListener());

    ayahWordAdapter = new AyahWordAdapter(ayahWordArrayList, getActivity(), surah_id);


    return view;
}