使用拖动调整视图大小并在释放时设置原始视图

时间:2015-05-11 07:09:42

标签: android android-activity

我想点击一个视图,当它被按下时,它需要在释放视图后缩小比例,它将回到它的宽度和高度 我怎么做..可以帮助任何人。

谢谢 Sajal Biswas 9903076025

1 个答案:

答案 0 :(得分:0)

OnTouchListener或覆盖View方法设置正确的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;
    }
});