Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PanView

The PanView class provides a utility to pan a view horizontally given the maximum pan bounds. It provides a smooth animation handling user touches. The view automatically snaps to the right or left depending on the point the user lifts his/her finger.

1 -> 2

Download: JAR library

Usage

When using this library, simply add the JAR to your project:

Right click on project --> Properties --> Java Build Path --> Libraries --> Add External JARs

Example

// View to enable touch based panning
final View view = findViewById(R.id.panView);
view.setOnTouchListener(mTouchListener);

// Button to quickly pan/unpan view
mPanButton = (Button) findViewById(R.id.panButton);
mPanButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        if (mPanView.isPanned()) {
            mPanView.hide();
        } else {
            mPanView.pan();
        }
    }
});

mPanView = new PanView(this, view);

// Listen to when the pan starts/ends and measure
mPanView.setOnPanListener(this);
mPanView.setOnMeasuredListener(this);

// PanView implements GestureDetector.OnGestureListener
mGestureDetector = new GestureDetector(this, mPanView);
mGestureDetector.setIsLongpressEnabled(false);

/**
 * Interface to provide the maximum right pan.
 */
@Override
public int getMaxRightPan() {
    return (int) getResources().getDimension(R.dimen.max_pan);
}

/**
 * Interface to provide the maximum left pan.
 */
@Override
public int getMaxLeftPan() {
    return 0;
}

OnTouchListener mTouchListener = new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        final int action = event.getAction();

        // Handle the up event
        if (mPanView.isFocused() && action == MotionEvent.ACTION_UP) {
            mPanView.onUp(event);
            return false;
        }

        // Let ViewController handle all touch events first
        if (mGestureDetector.onTouchEvent(event) || mPanView.isFocused()) {
            return false;
        }

        return true;
    }
};

To Do

  • Add functionality to support panning in top and bottom

License

About

Horizontal pan view.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages