Skip to content

Commit

Permalink
2015-3-11
Browse files Browse the repository at this point in the history
  • Loading branch information
guojunyi committed Mar 11, 2015
1 parent 9dec83b commit 84b64c6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
23 changes: 20 additions & 3 deletions PullDownListView/src/com/pulldownlistview/MainActivity.java
Expand Up @@ -46,7 +46,15 @@ public void onTopHeightChange(int headerHeight,
int pullHeight) {
// TODO Auto-generated method stub
float progress = (float) pullHeight
/ (float) headerHeight - 0.2f;
/ (float) headerHeight;

if(progress<0.5){
progress = 0.0f;
}else{
progress = (progress-0.5f)/0.5f;
}


if (progress > 1.0f) {
progress = 1.0f;
}
Expand All @@ -61,10 +69,18 @@ public void onBottomHeightChange(int footerHeight,
int pullHeight) {
// TODO Auto-generated method stub
float progress = (float) pullHeight
/ (float) footerHeight - 0.2f;
/ (float) footerHeight;

if(progress<0.5){
progress = 0.0f;
}else{
progress = (progress-0.5f)/0.5f;
}

if (progress > 1.0f) {
progress = 1.0f;
}

if (!pullDownListView.isRefreshing()) {
progressView.setProgress(progress);
}
Expand Down Expand Up @@ -136,12 +152,13 @@ public long getItemId(int position) {
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
TextView textView = new TextView(mContext);
textView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,dp2px(mContext,60)));
textView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,dp2px(mContext,50)));
textView.setText(adapterData[position]);
textView.setTextSize(20);
textView.setTextColor(0xff000000);
textView.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
textView.setPadding(50, 0, 0, 0);

return textView;
}

Expand Down
15 changes: 11 additions & 4 deletions PullDownListView/src/com/pulldownlistview/PullDownListView.java
Expand Up @@ -76,14 +76,18 @@ public boolean onTouchEvent(MotionEvent ev) {

int step = Math.abs(currentY - lastY);
lastY = currentY;

if (isTop && mListView.getTop() >= 0) {

if (isToBottom && mListView.getTop() <= MAX_PULL_TOP_HEIGHT) {
MotionEvent event = MotionEvent.obtain(ev);
ev.setAction(MotionEvent.ACTION_UP);
super.onTouchEvent(ev);
pullTag = true;

if(mListView.getTop()>layoutHeader.getHeight()){
step = step/2;
}
if ((mListView.getTop() + step) > MAX_PULL_TOP_HEIGHT) {
mCurrentY = MAX_PULL_TOP_HEIGHT;
scrollTopTo(mCurrentY);
Expand Down Expand Up @@ -117,6 +121,10 @@ public boolean onTouchEvent(MotionEvent ev) {
ev.setAction(MotionEvent.ACTION_UP);
super.onTouchEvent(ev);
pullTag = true;
if(parent.getHeight()-mListView.getBottom()>layoutFooter.getHeight()){
step = step/2;
}

if ((mListView.getBottom() - step) < (parent.getHeight()-MAX_PULL_BOTTOM_HEIGHT)) {
mCurrentY = -MAX_PULL_BOTTOM_HEIGHT;
scrollBottomTo(mCurrentY);
Expand Down Expand Up @@ -242,9 +250,8 @@ public void onMeasure(int widthMeasureSpec,int heightMeasureSpec){
REFRESHING_TOP_HEIGHT = layoutHeader.getMeasuredHeight();
REFRESHING_BOTTOM_HEIGHT = layoutFooter.getMeasuredHeight();

int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 38,this.getResources().getDisplayMetrics());
MAX_PULL_TOP_HEIGHT = REFRESHING_TOP_HEIGHT + value;
MAX_PULL_BOTTOM_HEIGHT = REFRESHING_BOTTOM_HEIGHT + value;
MAX_PULL_TOP_HEIGHT = this.getMeasuredHeight();
MAX_PULL_BOTTOM_HEIGHT = this.getMeasuredHeight();
}

@Override
Expand Down
Binary file modified apk/PullDownListView.apk
Binary file not shown.

0 comments on commit 84b64c6

Please sign in to comment.