Android 仿Moto菜菜绪商铺 点击图片缩放

对象的缩放效果如下:小编明日图片的八个文字点击点如下:现在自己曾经能达成朋友的这种缩放效果了,今后急需缓和的是,当本人的图片放大并活动到图片上八个文字地点后,会有一点击事件出来,这些相应从何入手呢?请教各位大佬..小编试过的秘诀是:在找到七个文字的中坚点坐标及半径Haval,来画圆做事件响应区域,不过,图片的缩放效果就未有了。一脸懵啊。。。

public class ScaleLinearlayout extends LinearLayout{
    public ScaleLinearlayout(Context context) {
        this(context,null);
    }

    public ScaleLinearlayout(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public ScaleLinearlayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }
}

图片 1

图片 2

只必要修正他的ontouch伊芙nt事件,让在那之中的图纸能够在点击的时候发出缩放效果。

四、可监察和控制TextView的实时滑动!

实例GIF

兑现那么些作用的基本思路如下:

float x=0,y=0;
AnimatorSet setDown, setMove, setUp;
@Override
    public boolean onTouchEvent(MotionEvent event) {

        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                for(int i=0;i<getChildCount();i++){
                    if(getChildAt(i) instanceof ImageView){
                        ImageView imageView= (ImageView) getChildAt(i);
                        ObjectAnimator animX=ObjectAnimator.ofFloat(imageView,"scaleX",1,1*0.85f);
                        ObjectAnimator animY=ObjectAnimator.ofFloat(imageView,"scaleY",1,1*0.85f);

                        setDown=new AnimatorSet();
                        setDown.play(animX).with(animY);
                        setDown.setDuration(300);
                        setDown.addListener(new AnimatorListenerAdapter() {    
                              @Override 
                              public void onAnimationStart(Animator animation) {      
                                    super.onAnimationStart(animation);    
                                    if (setUp != null && setUp.isRunning()) {  
                                          setUp.cancel(); 
                                           setUp = null;        
                                    }   
                             }
                          });
                          setDown.start();
                    }
                }

                break;
            case MotionEvent.ACTION_UP:

                    for(int i=0;i<getChildCount();i++){
                        if(getChildAt(i) instanceof ImageView){
                            ImageView imageView= (ImageView) getChildAt(i);
                            ObjectAnimator animX=ObjectAnimator.ofFloat(imageView,"scaleX",0.85f,1f);
                            ObjectAnimator animY=ObjectAnimator.ofFloat(imageView,"scaleY",0.85f,1f);

                            setUp=new AnimatorSet();
                            setUp.play(animX).with(animY);
                            setUp.setDuration(100);
                            setUp.addListener(new AnimatorListenerAdapter() {    
                              @Override 
                              public void onAnimationStart(Animator animation) {      
                                    super.onAnimationStart(animation);    
                                    if (setDown != null && setDown.isRunning()) {  
                                          setDown.cancel(); 
                                           setDown = null;        
                                    }   
                             }
                          });
                            setUp.start();
                        }
                    }

                break;
        }
        return true;
    }

这一次就不上代码了,感兴趣的去github上下载源码吧。以为好的,给个赞哦!哈哈

float x=0,y=0;
boolean canMove=true;
AnimatorSet setDown, setMove, setUp;
@Override
public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                canMove=true;
                x=event.getX();
                y=event.getY();
                for(int i=0;i<getChildCount();i++){
                    if(getChildAt(i) instanceof ImageView){
                        ImageView imageView= (ImageView) getChildAt(i);
                        ObjectAnimator animX=ObjectAnimator.ofFloat(imageView,"scaleX",1,1*0.85f);
                        ObjectAnimator animY=ObjectAnimator.ofFloat(imageView,"scaleY",1,1*0.85f);

                        setDown=new AnimatorSet();
                        setDown.play(animX).with(animY);
                        setDown.setDuration(300);
                        setDown.addListener(new AnimatorListenerAdapter() {    
                              @Override 
                              public void onAnimationStart(Animator animation) {      
                                    super.onAnimationStart(animation);    
                                    if (setUp != null && setUp.isRunning()) {  
                                          setUp.cancel(); 
                                           setUp = null;        
                                    }  
                                    if (setMove != null && setMove.isRunning()) {  
                                          setMove.cancel(); 
                                           setMove = null;        
                                    }  
                             }
                          });
                        setDown.start();
                    }
                }

                break;

            case MotionEvent.ACTION_MOVE:
                if(canMove&&Math.hypot(Math.abs(event.getX()-x),Math.abs(event.getY()-y))>ViewConfiguration.get(getContext()).getScaledTouchSlop()){
                    canMove=false;
                    for(int i=0;i<getChildCount();i++){
                        if(getChildAt(i) instanceof ImageView){
                            ImageView imageView= (ImageView) getChildAt(i);
                            ObjectAnimator animX=ObjectAnimator.ofFloat(imageView,"scaleX",0.85f,1f);
                            ObjectAnimator animY=ObjectAnimator.ofFloat(imageView,"scaleY",0.85f,1f);

                            setMove=new AnimatorSet();
                            setMove.play(animX).with(animY);
                            setMove.setDuration(100);
                            setMove.addListener(new AnimatorListenerAdapter() {    
                              @Override 
                              public void onAnimationStart(Animator animation) {      
                                    super.onAnimationStart(animation);    
                                    if (setDown != null && setDown.isRunning()) {  
                                          setDown.cancel(); 
                                           setDown = null;        
                                    }   
                             }
                          });
                            setMove.start();
                        }
                    }
                }

                break;

            case MotionEvent.ACTION_UP:
                if(canMove){
                    for(int i=0;i<getChildCount();i++){
                        if(getChildAt(i) instanceof ImageView){
                            ImageView imageView= (ImageView) getChildAt(i);
                            ObjectAnimator animX=ObjectAnimator.ofFloat(imageView,"scaleX",0.85f,1f);
                            ObjectAnimator animY=ObjectAnimator.ofFloat(imageView,"scaleY",0.85f,1f);

                            setUp=new AnimatorSet();
                            setUp.play(animX).with(animY);
                            setUp.setDuration(100);
                            setUp.addListener(new AnimatorListenerAdapter() {    
                              @Override 
                              public void onAnimationStart(Animator animation) {      
                                    super.onAnimationStart(animation);    
                                    if (setDown != null && setDown.isRunning()) {  
                                          setDown.cancel(); 
                                           setDown = null;        
                                    }   
                             }
                          });
                            setUp.start();
                        }
                    }

                }

                break;
        }
        return true;
 }

率先,大家商酌在MyView上海好笑剧团动完结对TextView的缩放和旋转操作。当大家有四个以上的手指触摸view的时候,菜具备触发缩放和旋转的尺度,那个时候,我们需求监听ACTION_DOWN和ACTION_POINTER_DOWN,假设三个事件同有的时候间触发,表达有五个手指头,当时咱们纪录下刚落点时的三个点的坐标,然后在三个手指的滑行进度中,我们在ACTINON_MOVE事件中去动态的收获滑动中的八个点的坐标,然后实时的去总括多个点时期的离开,再与事情发生前的离开举办比较,倘诺比早前的打大,表达顾客的筹划是放手,反之正是压缩,于此同期,总计七个点之间的连线与事情未发生前七个点时期点连线的角度,再依赖总体总括出来的角度对TextView实行旋转操作。

一、点击自定义View能够创立标签,点击标签滑动能够改造标签地点;

图片 3

大家须要关切的是MotionEvent.ACTION_DOWN,MotionEvent.ACTION_MOVE,MotionEvent.ACTION_UP,MotionEvent.ACTION_POINTER_UP,MotionEvent.ACTION_POINTER_DOWN,MotionEvent.ACTION_CANCEL.

在看下大家最后完毕的样式:

六、点击保存能将画布生成图片保存下去!