Locking Scroll Of Gridview
I have one gridview in my UI but it scrolls vertically I have set all the scrollbar properties as false but its still scrolling. Any idea why this is so? please help. This is my la
Solution 1:
Try to add or override setOnTouchListener
for GridView, then in onTouch method you can use code like this to make gridview not scrolling :
gridview.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_MOVE){
return true;
}
return false;
}
});
Solution 2:
Use this custom gridview. It automatically sets the height and does not scroll:
public class MyGridView extends GridView {
public MyGridView(Context context) {
super(context);
}
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightSpec;
if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
// The great Android "hackatlon", the love, the magic.
// The two leftmost bits in the height measure spec have
// a special meaning, hence we can't use them to describe height.
heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
} else {
heightSpec = heightMeasureSpec;
}
super.onMeasure(widthMeasureSpec, heightSpec);
}
}
Solution 3:
GridView
is designed to scroll vertically, and I am not aware that you can stop it from scrolling. If you do not want scrolling, do not use a GridView
.
Solution 4:
public class myGridView extends GridView {
public myGridView(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
return super.onTouchEvent(event);
case MotionEvent.ACTION_MOVE:
//Do nothing here!!!
break;
case MotionEvent.ACTION_UP:
return super.onTouchEvent(event);
}
//false return
return false;
}
}
Post a Comment for "Locking Scroll Of Gridview"