【问题标题】:Resize a view with drag and set original while release通过拖动调整视图大小并在释放时设置原始视图
【发布时间】:2015-07-21 14:19:09
【问题描述】:

我想点击一个视图,当它被按下时,它需要在释放视图后按比例缩小,它会恢复到它的宽度和高度我该怎么办?谁能帮忙?

【问题讨论】:

    标签: android android-view android-custom-view


    【解决方案1】:

    为您的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;
        }
    });
    

    【讨论】:

    • 如果它解决了您的问题,请随时接受答案。
    猜你喜欢
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    相关资源
    最近更新 更多