Posts

Showing posts with the label Android Recyclerview

Android : Control Smooth Scroll Over Recycler View

Answer : It's unclear what you mean when you say " smoothScroll ". You could be referring to the automatic " smoothScrollToPosition " which will automatically scroll to a specified position, you could be talking about manual scrolling and you could be talking about flinging. For the sake of prosperity, I will attempt to answer all of these issues now. 1. Automatic smooth scrolling. Inside your layout manager, you need to implement the smoothScrollToPosition method: @Override public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) { // A good idea would be to create this instance in some initialization method, and just set the target position in this method. LinearSmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) { @Override public PointF computeScrollVectorForPosition(int targetPosition) { int yDelta = calculateC...

Android Horizontal RecyclerView Scroll Direction

Answer : Assuming you use LinearLayoutManager in your RecyclerView, then you can pass true as third argument in the LinearLayoutManager constructor. For example: mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true)); If you are using the StaggeredGridLayoutManager , then you can use the setReverseLayout method it provides. You can do it with just xml. the app:reverseLayout="true" do the job! <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="@null" android:orientation="horizontal" app:reverseLayout="true" app:layoutManager="android.support.v7.widget.LinearLayoutManager" /> XML approach using androidx: <androidx.recyclerview....