我的代码中有问题,setOnScrollListener似乎从未被调用过,因为当我滚动我的relativelayout时不会隐藏,而且我没有看到logcat中的日志。
这是我的代码:
list = (ListView)findViewById(R.id.accountview_listview);
adapter = new Account_view_custom_adapter(Account_view_act.this, annoncesList);
list.setAdapter(adapter);
adapter.notifyDataSetChanged();
registerForContextMenu(list);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
list.showContextMenuForChild(view);
}
});
list.setOnScrollListener(new OnScrollListener() {
int mPosition=0;
int mOffset=0;
RelativeLayout relative1 = (RelativeLayout) findViewById(R.id.relative1);
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
int position = list.getFirstVisiblePosition();
View v = list.getChildAt(0);
int offset = (v == null) ? 0 : v.getTop();
if (mPosition < position || (mPosition == position && mOffset < offset)){
// Scrolled up
Log.d("INFO", "UP");
relative1.setVisibility(View.GONE);
} else {
// Scrolled down
Log.d("INFO", "DOWN");
relative1.setVisibility(View.VISIBLE);
}
}
});