android 仿饿了吗下拉刷新
2个回答
推荐于2016-01-15 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517193
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
代码部分如下:
package com.jefry;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;
public class NetNewDemo extends Activity {
public static ImageView fresh = null;
View mRefreshView;
int top = 0;
int first = 0;
TextView mRefreshViewText;
ImageView mRefreshViewImage;
ImageView mImageView;
ProgressBar mRefreshViewProgress;
TextView mRefreshViewLastUpdated;
Handler hand = new Handler(){
public void handleMessage(android.os.Message msg) {
mRefreshViewImage.setVisibility(View.GONE);
mImageView.setVisibility(View.GONE);
mRefreshView.setPadding(mRefreshView.getPaddingLeft(),0,mRefreshView.getPaddingRight(),mRefreshView.getPaddingBottom());
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mRefreshView = (View)findViewById(R.id.layout);
mRefreshViewImage = (ImageView) findViewById(R.id.pull_to_refresh_image);
mImageView = (ImageView)findViewById(R.id.going);
ScrollView sc = (ScrollView)findViewById(R.id.scroll);
sc.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent event) {
Log.i("TAG", "=============onTouchEvent=================");
//当前手指的Y值
final int y = (int) event.getY();
// mRefreshViewImage.setImageResource(R.drawable.fresh_going);
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
try{
first = 0;
mRefreshViewImage.setImageResource(R.drawable.fresh_going);
mRefreshView.setPadding(mRefreshView.getPaddingLeft(),0,mRefreshView.getPaddingRight(),mRefreshView.getPaddingBottom());
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
}
hand.sendEmptyMessage(1);
}
}).start();
}catch (Exception e) {}
break;
case MotionEvent.ACTION_DOWN:
first = y;
break;
case MotionEvent.ACTION_MOVE:
mImageView.setVisibility(View.GONE);
int instance = y-first;
if(instance>0 && instance < 30) {
mRefreshViewImage.setVisibility(View.VISIBLE);
mRefreshViewImage.setImageResource(R.drawable.down);
} else if(instance >=30){
mRefreshViewImage.setVisibility(View.VISIBLE);
mRefreshViewImage.setImageResource(R.drawable.fresh_before);
}
mRefreshView.setPadding(mRefreshView.getPaddingLeft(),instance,mRefreshView.getPaddingRight(),mRefreshView.getPaddingBottom());
//mRefreshViewImage.setImageResource(R.drawable.fresh_going);
break;
}
return true;
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.i("TAG", "=============onTouchEvent=================");
//当前手指的Y值
final int y = (int) event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
first = 0;
prepareForRefresh(); //准备刷新
break;
case MotionEvent.ACTION_DOWN:
first = y;
break;
case MotionEvent.ACTION_MOVE:
//更行头视图的toppadding 属性
Log.i("TAG", "=============ACTION_MOVE============" + (y - first));
mRefreshView.setPadding(mRefreshView.getPaddingLeft(),(y - first),mRefreshView.getPaddingRight(),mRefreshView.getPaddingBottom());
//applyHeaderPadding(event);
break;
}
return super.onTouchEvent(event);
}
public void prepareForRefresh() {
resetHeaderPadding(); //初始化,头部文件
mRefreshViewImage.setVisibility(View.GONE);
mRefreshViewImage.setImageDrawable(null);
mRefreshViewProgress.setVisibility(View.VISIBLE);
mRefreshViewText.setText("Jefry ");
}
private void resetHeaderPadding() {
mRefreshView.setPadding(
mRefreshView.getPaddingLeft(),
0,
mRefreshView.getPaddingRight(),
mRefreshView.getPaddingBottom());
}
}
package com.jefry;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;
public class NetNewDemo extends Activity {
public static ImageView fresh = null;
View mRefreshView;
int top = 0;
int first = 0;
TextView mRefreshViewText;
ImageView mRefreshViewImage;
ImageView mImageView;
ProgressBar mRefreshViewProgress;
TextView mRefreshViewLastUpdated;
Handler hand = new Handler(){
public void handleMessage(android.os.Message msg) {
mRefreshViewImage.setVisibility(View.GONE);
mImageView.setVisibility(View.GONE);
mRefreshView.setPadding(mRefreshView.getPaddingLeft(),0,mRefreshView.getPaddingRight(),mRefreshView.getPaddingBottom());
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mRefreshView = (View)findViewById(R.id.layout);
mRefreshViewImage = (ImageView) findViewById(R.id.pull_to_refresh_image);
mImageView = (ImageView)findViewById(R.id.going);
ScrollView sc = (ScrollView)findViewById(R.id.scroll);
sc.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent event) {
Log.i("TAG", "=============onTouchEvent=================");
//当前手指的Y值
final int y = (int) event.getY();
// mRefreshViewImage.setImageResource(R.drawable.fresh_going);
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
try{
first = 0;
mRefreshViewImage.setImageResource(R.drawable.fresh_going);
mRefreshView.setPadding(mRefreshView.getPaddingLeft(),0,mRefreshView.getPaddingRight(),mRefreshView.getPaddingBottom());
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
}
hand.sendEmptyMessage(1);
}
}).start();
}catch (Exception e) {}
break;
case MotionEvent.ACTION_DOWN:
first = y;
break;
case MotionEvent.ACTION_MOVE:
mImageView.setVisibility(View.GONE);
int instance = y-first;
if(instance>0 && instance < 30) {
mRefreshViewImage.setVisibility(View.VISIBLE);
mRefreshViewImage.setImageResource(R.drawable.down);
} else if(instance >=30){
mRefreshViewImage.setVisibility(View.VISIBLE);
mRefreshViewImage.setImageResource(R.drawable.fresh_before);
}
mRefreshView.setPadding(mRefreshView.getPaddingLeft(),instance,mRefreshView.getPaddingRight(),mRefreshView.getPaddingBottom());
//mRefreshViewImage.setImageResource(R.drawable.fresh_going);
break;
}
return true;
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.i("TAG", "=============onTouchEvent=================");
//当前手指的Y值
final int y = (int) event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
first = 0;
prepareForRefresh(); //准备刷新
break;
case MotionEvent.ACTION_DOWN:
first = y;
break;
case MotionEvent.ACTION_MOVE:
//更行头视图的toppadding 属性
Log.i("TAG", "=============ACTION_MOVE============" + (y - first));
mRefreshView.setPadding(mRefreshView.getPaddingLeft(),(y - first),mRefreshView.getPaddingRight(),mRefreshView.getPaddingBottom());
//applyHeaderPadding(event);
break;
}
return super.onTouchEvent(event);
}
public void prepareForRefresh() {
resetHeaderPadding(); //初始化,头部文件
mRefreshViewImage.setVisibility(View.GONE);
mRefreshViewImage.setImageDrawable(null);
mRefreshViewProgress.setVisibility(View.VISIBLE);
mRefreshViewText.setText("Jefry ");
}
private void resetHeaderPadding() {
mRefreshView.setPadding(
mRefreshView.getPaddingLeft(),
0,
mRefreshView.getPaddingRight(),
mRefreshView.getPaddingBottom());
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-12-19
展开全部
没明白你说的什么意思
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询