Created
June 15, 2017 16:58
-
-
Save tank777/739eafaf0708ffe1682f4409e1a0d866 to your computer and use it in GitHub Desktop.
stop recyclerview scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bgt.stopscrollrecycleview; | |
import android.content.Context; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.util.AttributeSet; | |
/** | |
* Created by Bhavesh on 15-06-2017. | |
*/ | |
public class CustomLinearLayoutManager extends LinearLayoutManager { | |
private boolean isScrollEnabled = true; | |
public CustomLinearLayoutManager(Context context) { | |
super(context); | |
} | |
public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { | |
super(context, orientation, reverseLayout); | |
} | |
public CustomLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | |
super(context, attrs, defStyleAttr, defStyleRes); | |
} | |
public void setScrollEnabled(boolean flag) { | |
this.isScrollEnabled = flag; | |
} | |
@Override | |
public boolean canScrollHorizontally() { | |
//Similarly you can customize "canScrollHorizontally()" for managing horizontal scroll | |
return isScrollEnabled && super.canScrollHorizontally(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bgt.stopscrollrecycleview; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.View; | |
public class MainActivity extends AppCompatActivity { | |
RecyclerView recyclerView; | |
TestAdapter testAdapter; | |
CustomLinearLayoutManager lm; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
recyclerView = (RecyclerView) findViewById(R.id.rv_test); | |
lm = new CustomLinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL,false); | |
lm.setScrollEnabled(false); | |
recyclerView.setLayoutManager(lm); | |
testAdapter = new TestAdapter(); | |
recyclerView.setAdapter(testAdapter); | |
recyclerView.stopScroll(); | |
} | |
public void mShowMore(View view) { | |
lm.setScrollEnabled(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment