当用户在屏幕上向下移动手指时,我想更改视图高度。
new OnTouchListener() {
float lastY = Float.MIN_VALUE;
@Override
public boolean onTouch(View v, MotionEvent event) {
if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_MOVE) {
if (lastY != Float.MIN_VALUE) {
final float dist = event.getRawY() - lastY;
myView.post(new Runnable() {
@Override
public void run() {
ViewGroup.LayoutParams lp = myView.getLayoutParams();
lp.height += dist;
myView.setLayoutParams(lp);
}
});
view.invalidate();
}
lastY = event.getRawY();
}
if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
lastY = Float.MIN_VALUE;
}
return true;
}
}
但是只有当用户停止移动手指时视图高度才会改变!
发生 ACTION_MOVE 时如何立即更改视图高度?