Comments (4)
I added the support in my version https://github.com/GoMino/StaggeredGridView, I still need to merge the code with this version of the StaggeredGridView, I based mine on the original one in the support library.
from staggeredgridview.
I also need this feature. The above fork does include it, but it seems to be missing a lot of the functionality in the main version right now (like onItemClick).
from staggeredgridview.
@justinmc you can add GoMino code:
paste this before return of onTouchEvent of maurycyw
switch (action)
{
case MotionEvent.ACTION_DOWN:
mVelocityTracker.clear();
mScroller.abortAnimation();
mLastTouchY = ev.getY();
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
mTouchRemainderY = 0;
break;
case MotionEvent.ACTION_MOVE:
{
final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
if (index < 0)
{
Log.e(TAG, "onInterceptTouchEvent could not find pointer with id "
+ mActivePointerId
+ " - did StaggeredGridView receive an inconsistent " + "event stream?");
return false;
}
final float y = MotionEventCompat.getY(ev, index);
final float dy = y - mLastTouchY + mTouchRemainderY;
final int deltaY = (int) dy;
mTouchRemainderY = dy - deltaY;
if (Math.abs(dy) > mTouchSlop)
{
setTouchMode(TOUCH_MODE_DRAGGING);
}
if (mTouchMode == TOUCH_MODE_DRAGGING)
{
mLastTouchY = y;
if (!trackMotionScroll(deltaY, true))
{
// Break fling velocity if we impacted an edge.
mVelocityTracker.clear();
}
}
}
break;
case MotionEvent.ACTION_CANCEL:
setTouchMode(TOUCH_MODE_IDLE);
break;
case MotionEvent.ACTION_UP:
{
mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker,
mActivePointerId);
if (Math.abs(velocity) > mFlingVelocity)
{ // TODO
setTouchMode(TOUCH_MODE_FLINGING);
mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
mLastTouchY = 0;
ViewCompat.postInvalidateOnAnimation(this);
}
else
{
setTouchMode(TOUCH_MODE_IDLE);
}
}
break;
}
and in class add interface
public void setTouchMode(int newState){
// mTouchMode = newState;
switch (newState) {
case TOUCH_MODE_DRAGGING:
reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
break;
case TOUCH_MODE_FLINGING:
reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
break;
case TOUCH_MODE_IDLE:
reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
break;
}
}
private OnScrollListener mOnScrollListener;
public void setOnScrollListener(OnScrollListener scrollListener) {
mOnScrollListener = scrollListener;
invokeOnItemScrollListener();
}
void reportScrollStateChange(int newState) {
if (newState != mTouchMode) {
mTouchMode = newState;
if (mOnScrollListener != null) {
mOnScrollListener.onScrollStateChanged(this, newState);
}
}
}
void invokeOnItemScrollListener() {
if (mOnScrollListener != null) {
mOnScrollListener.onScroll(this, mFirstPosition, getChildCount(), mItemCount);
}
}
/**
* Interface definition for a callback to be invoked when the list or grid
* has been scrolled.
*/
public interface OnScrollListener {
/**
* The view is not scrolling. Note navigating the list using the trackball counts as
* being in the idle state since these transitions are not animated.
*/
public static int SCROLL_STATE_IDLE = 0;
/**
* The user is scrolling using touch, and their finger is still on the screen
*/
public static int SCROLL_STATE_TOUCH_SCROLL = 1;
/**
* The user had previously been scrolling using touch and had performed a fling. The
* animation is now coasting to a stop
*/
public static int SCROLL_STATE_FLING = 2;
/**
* Callback method to be invoked while the list view or grid view is being scrolled. If the
* view is being scrolled, this method will be called before the next frame of the scroll is
* rendered. In particular, it will be called before any calls to
* {@link Adapter#getView(int, View, ViewGroup)}.
*
* @param view The view whose scroll state is being reported
*
* @param scrollState The current scroll state. One of {@link #SCROLL_STATE_IDLE},
* {@link #SCROLL_STATE_TOUCH_SCROLL} or {@link #SCROLL_STATE_IDLE}.
*/
public void onScrollStateChanged(ViewGroup view, int scrollState);
/**
* Callback method to be invoked when the list or grid has been scrolled. This will be
* called after the scroll has completed
* @param view The view whose scroll state is being reported
* @param firstVisibleItem the index of the first visible cell (ignore if
* visibleItemCount == 0)
* @param visibleItemCount the number of visible cells
* @param totalItemCount the number of items in the list adaptor
*/
public void onScroll(ViewGroup view, int firstVisibleItem, int visibleItemCount, int totalItemCount);
}
both things worked like charm for me. Didn't had time to merge
from staggeredgridview.
I did the same thing just using the AbsListView.OnScrollListener because libs like Universal Image Loader are based on that for pausing loading and so on.
private OnScrollListener mOnScrollListener;
public OnScrollListener getOnScrollListener() {
return mOnScrollListener;
}
public void setOnScrollListener(OnScrollListener onScrollListener) {
mOnScrollListener = onScrollListener;
}
public void setTouchMode(int touchMode) {
if (mOnScrollListener != null) {
if (touchMode == TOUCH_MODE_IDLE && mTouchMode != TOUCH_MODE_IDLE) {
mOnScrollListener.onScrollStateChanged(null, OnScrollListener.SCROLL_STATE_IDLE);
} else if (touchMode == TOUCH_MODE_DRAGGING && mTouchMode != TOUCH_MODE_DRAGGING) {
mOnScrollListener.onScrollStateChanged(null, OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
} else if (touchMode == TOUCH_MODE_FLINGING && mTouchMode != TOUCH_MODE_FLINGING) {
mOnScrollListener.onScrollStateChanged(null, OnScrollListener.SCROLL_STATE_FLING);
}
}
mTouchMode = touchMode;
}
setTouchMode() is called everywhere the state changes between these three modes.
from staggeredgridview.
Related Issues (20)
- Staggered Grid View Height issue
- add scrollbar
- Having issue while using custom Typeface, it affects smooth scrolling of StaggeredGridView
- setOnItemLongClickListener not work's :/
- Header, Footer is not supported HOT 1
- notifyDataSetChanged not working HOT 2
- DPad Selection
- Error in StaggeredGridView.java
- Is there any way to display vertical scroll bar?
- ArrayIndexOutOfBoundsException
- SGV.onMeasure() does not recalculate mColumnTops/Bottoms/Lefts when SGV dimension changes HOT 2
- Set listSelector HOT 1
- auto set width and height StaggeredGridView Item
- No SetSelection(int index) method HOT 2
- Cannot show content below staggered gridview HOT 1
- scrollbar
- SwipeRefreshLayout HOT 3
- Missing support for RTL layout
- Is it possible to set a header view crossing columns?
- Error inflating class com.origamilabs.library.views.StaggeredGridView
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from staggeredgridview.