我在交错的网格视图中使用了手写拉动来刷新库。它工作正常但现在我希望网格视图自己垂直移动,当它移动时甚至在该用户之后应该能够拉动由于网格视图的移动。但它没有用。
我使用的代码是:pullToRefreshStaggeredGrid=(PullToRefreshStaggeredGridView) findViewById(R.id.staggeredGridView1);
staggeredGridView=pullToRefreshStaggeredGrid.getRefreshableView();
int margin = getResources().getDimensionPixelSize(R.dimen.margin);
staggeredGridView.setItemMargin(margin); // set the GridView margin
staggeredGridView.setPadding(margin, 0, margin, 0); // have the margin on the sides as well
adapter = new StaggeredAdapter(MainActivity.this, R.id.imageView1,urls,imageLoader);
new AsyncClass().execute(count);
}
AND ASYNC CLASS IS:
private class AsyncClass extends AsyncTask<Integer, Void, Integer>
{
@Override
protected Integer doInBackground(Integer... params) {
publishProgress();
return params[0];
}
@Override
protected void onProgressUpdate(Void... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
staggeredGridView.setAdapter(adapter);
}
@Override
protected void onPostExecute(Integer result) {
// TODO Auto-generated method stub
count=result;
Log.e("count","count"+count);
final Timer timer = new Timer();
final Handler handler=new Handler();
timer.scheduleAtFixedRate(
new java.util.TimerTask() {
final long t0=System.currentTimeMillis();
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
Log.e("timer","timer");
staggeredGridView.scrollTo(0, count);
count=count+10;
pullToRefreshStaggeredGrid.setRefreshing(false);
}
});
if(System.currentTimeMillis()-t0>5 * 1000)
{
Log.e("cancel","cancel");
timer.cancel();
}
}
},200,100
);
}
}
答案 0 :(得分:0)
使用新的pull to refresh(https://github.com/chrisbanes/ActionBar-PullToRefresh),您可以使用自定义ViewDelegate并检查StaggeredGridView中的第一个视图是否具有位置0并且是否滚动到顶部(getTop()== sgv.getItemMargin())。