【发布时间】:2015-07-21 14:19:09
【问题描述】:
我想点击一个视图,当它被按下时,它需要在释放视图后按比例缩小,它会恢复到它的宽度和高度我该怎么办?谁能帮忙?
【问题讨论】:
标签: android android-view android-custom-view
我想点击一个视图,当它被按下时,它需要在释放视图后按比例缩小,它会恢复到它的宽度和高度我该怎么办?谁能帮忙?
【问题讨论】:
标签: android android-view android-custom-view
为您的View 设置适当的OnTouchListener 或覆盖onTouchEvent 方法(如果它是自定义视图)。像这样(示例由第一种方法组成):
yourView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// apply the change to the dimensions of your view;
// for example with animation and using scale parameters, like this:
v.animate().scaleX(0.6f).scaleY(0.6f);
return true;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
// revert to the normal dimensions of your view
// for example with animation and using scale parameters, like this:
v.animate().scaleX(1f).scaleY(1f);
break;
}
return false;
}
});
【讨论】: