Skizit
Skizit

Reputation: 44852

Android Custom gallery to disable scrolling

I'm attempting to create a custom Gallery to disable scrolling. I've got the following from this: how to disable gallery view scrolling

 public class MyGallery extends Gallery{


public MyGallery(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){
    if (isSelected())
        return true;
    else return super.onFling(e1, e2, velocityX, velocityY);
    }

}

Doesn't seem to be working. What am I doing wrong?

Upvotes: 5

Views: 1485

Answers (2)

Parag Chauhan
Parag Chauhan

Reputation: 35946

I have use CustomListview in Linearlayout. and disable scrolling using below code

public void enableDisableView(View view, boolean enabled) {
        view.setEnabled(enabled);

        if ( view instanceof ViewGroup ) {
            ViewGroup group = (ViewGroup)view;

            for ( int idx = 0 ; idx < group.getChildCount() ; idx++ ) {
                enableDisableView(group.getChildAt(idx), enabled);
            }
        }
    }

Upvotes: 0

Pēteris Caune
Pēteris Caune

Reputation: 45112

Note the if (isSelected()) clause in example, you might want to omit that and return true unconditionally, completely avoiding inherited implementation.

Overriding onFling prevents flings but doesn't affect regular scrolling, with finger down. To do that, try also overriding onScroll and immediately returning true from there.

If that doesn't work either, you can also override onTouchEvent and filter touch events there.

Upvotes: 2

Related Questions