Search code examples
androidscale

How to test for ScaleType?


Is there a way to test for ScaleType? I was thinking something along the lines of:

public View makeView() {

        ImageView i = new ImageView(this);
        i.setScaleType(ScaleType.FIT_XY);
}

i.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        ImageView i = (ImageView) v;
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                if (i.setScaleType() == FIT_XY){
                    ...
                }
        }

Not sure if this is syntactically possible. Looking forward to your suggestions. What i'm attempting to do, essentially, is only enable drag (via the switch/case) if scaleType != FIT_XY...


Solution

  • ImageView has a getScaleType() method too. That will return to you the type I would assume.

    case MotionEvent.ACTION_DOWN:
        if (i.getScaleType() == ScaleType.FIT_XY){
            ...
        }
    

    This should give you the behavior your looking for.

    Also check out the Javadoc for ImageView