1:android:layout_marginTop="-100dp"给列表头是图片的列表加个这个属性有下拉弹起的效果
2:计算列表下拉的距离(如果所有列表项长度一样的话可行)
public int getScrollY() {
View c = myPullListView.getChildAt(0);
if (c == null) {
return 0;
}
int firstVisiblePosition = myPullListView.getFirstVisiblePosition();
int top = c.getTop();
System.out.println(c.getHeight());
return -top + (firstVisiblePosition-1) * c.getHeight() ;
}
3:scrollView滑动距离计算
当手势缓慢滑动时scrollView.getScrollY()即可计算出滑动距离.
当手势快速滑动时,手势已ACTION_UP,但scrollView仍会继续滑动,此时就要通过隔一段时候计算一下scrollView.getScrollY(),当它不变时才表示不再滑动
scrollView.setOnTouchListener(new OnTouchListener() {
private int lastY = 0;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (lastY == scrollView.getScrollY()) {
ChangeTitle();
} else {
lastY = scrollView.getScrollY();
ChangeTitle();
handler.sendEmptyMessageDelayed(0, 300);
}
}
};
private void ChangeTitle() {
System.out.println("scrollView.getScrollY"+scrollView.getScrollY());
if (Util.px2dip(StoreDetailActivity.this, scrollView.getScrollY()) > 146) {
title.setBackgroundColor(Color.parseColor("#ffffff"));
} else {
title.setBackgroundColor(Color.parseColor("#00ffffff"));
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
int eventAction = event.getAction();
switch (eventAction) {
case MotionEvent.ACTION_UP:
handler.sendEmptyMessage(0);
break;
case MotionEvent.ACTION_MOVE:
ChangeTitle();
default:
break;
}
return false;
}
});
4:"#00ffffff"表示完全透明,00改成ff则是完全不透明