If you try to get the float type by dividing it, you get 1.0.

Asked 2 months ago, Updated 2 months ago, 3 views

I am using TouchImageView on Android.
I'd like to calculate the zoom value on the large/small side of the image.

when outputting in code width770 height1035
1.0
The 1035/770 is now 1.0.

contentImage.setOnDoubleTapListener(newGestureDetector.OnDoubleTapListener(){
@ Override
public boolean onSingleTapConfirmed (MotionEvent) {
    return true;
}

@ Override
public boolean onDoubleTap (MotionEvent) {
    int width=contentImage.getDrawable().getIntrinsicWidth();
    intheight=contentImage.getDrawable().getIntrinsicHeight();
    System.out.println("width" + width);
    System.out.println("height" + height);
    int max = Math.max (width, height);
    int min = Math.min (width, height);
    float zoom=max/min;
    System.out.println(zoom);
    contentImage.setZoom(max/min);
    return false;
}

@ Override
public boolean onDoubleTapEvent (MotionEvent) {
    return true;
}});

android

2022-09-30 11:42

1 Answers

Because the variables max and min are of type int, I think max/min is interpreted as an integer (compiler) and the result is an integer (int).

I think max and min should be of the float type.


2022-09-30 11:42

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.