ListView hide the part of headerView
2015-04-02 16:59
274 查看
private int measureHeight;
private float lastY = 0;
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
final int action = event.getAction();
if (null == mLinearLayout) {
return super.dispatchTouchEvent(event);
}
float y = event.getY();
int mHeight = mLinearLayout.getHeight();
switch (action) {
case MotionEvent.ACTION_DOWN:
if (measureHeight == 0) {
measureHeight = mLinearLayout.getHeight();
}
break;
case MotionEvent.ACTION_MOVE:
if (mListView.getFirstVisiblePosition() <= 0
|| (mListView.getFirstVisiblePosition() > 0 && mHeight > 0)) {
if (lastY == 0) {
lastY = y;
}
float diffY = y - lastY;
int offset = 0;
if (diffY < 0 && mHeight > 0 && mHeight <= measureHeight) {
float scrollY = diffY - (measureHeight - mHeight);
offset = (int) (Math.abs(scrollY) <= measureHeight ? scrollY : -measureHeight);
mLinearLayout.setPadding(0, offset, 0, 0);
}
if (diffY > 0 && mHeight <= measureHeight) {
float scrollY = diffY - measureHeight + mHeight;
offset = (int) (Math.abs(scrollY + measureHeight) <= measureHeight ? scrollY
: 0);
mLinearLayout.setPadding(0, offset, 0, 0);
}
}
break;
case MotionEvent.ACTION_UP:
lastY = 0;
break;
default:
return super.dispatchTouchEvent(event);
}
return super.dispatchTouchEvent(event);
}
private float lastY = 0;
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
final int action = event.getAction();
if (null == mLinearLayout) {
return super.dispatchTouchEvent(event);
}
float y = event.getY();
int mHeight = mLinearLayout.getHeight();
switch (action) {
case MotionEvent.ACTION_DOWN:
if (measureHeight == 0) {
measureHeight = mLinearLayout.getHeight();
}
break;
case MotionEvent.ACTION_MOVE:
if (mListView.getFirstVisiblePosition() <= 0
|| (mListView.getFirstVisiblePosition() > 0 && mHeight > 0)) {
if (lastY == 0) {
lastY = y;
}
float diffY = y - lastY;
int offset = 0;
if (diffY < 0 && mHeight > 0 && mHeight <= measureHeight) {
float scrollY = diffY - (measureHeight - mHeight);
offset = (int) (Math.abs(scrollY) <= measureHeight ? scrollY : -measureHeight);
mLinearLayout.setPadding(0, offset, 0, 0);
}
if (diffY > 0 && mHeight <= measureHeight) {
float scrollY = diffY - measureHeight + mHeight;
offset = (int) (Math.abs(scrollY + measureHeight) <= measureHeight ? scrollY
: 0);
mLinearLayout.setPadding(0, offset, 0, 0);
}
}
break;
case MotionEvent.ACTION_UP:
lastY = 0;
break;
default:
return super.dispatchTouchEvent(event);
}
return super.dispatchTouchEvent(event);
}
相关文章推荐
- WPF _Make ListView.ScrollIntoView Scroll the Item into the Center of the ListView (C#)
- 使用js隐藏GridView的表头(hide the table header of GridView by JS)
- The Adapter of ListView: Just adapt data to view, don’t do anything else
- The power of TextView (Part 1): Drawables
- 使用js隐藏GridView的表头(hide the table header of GridView by JS)
- The Adapter of ListView: Just adapt data to view, don’t do anything else
- How can I insert a checkbox into the header of my view?
- The Adapter of ListView: Just adapt data to view, don’t do anything else
- how to javafx hide background header of a tableview?
- (Sharepoint 2010) Change the background and font color of text for a web part header
- hide the scrollbars of TWebBrowser?
- [转载]Reading part of the 'Image' Sql Server BLOB
- Selected solutions to exercise of "The C Programming Language" 2e (Part 7, End of Chapter 1)
- Business analysis and SOA part 4 of 6: SOA delivery lifecycle and the top-down approach [by Thomas Erl]
- A review of the Zend Framework - Part 1
- Business analysis and SOA part 1 of 6: The benefits of business services [by Thomas Erl]
- CSV ----- To improve the performance of Excel Output with reflection (Part 1)
- 4:55 part of the game
- The Imminent Demise of the Page View
- A review of the Zend Framework - Part 2