1
When I create the project it comes like this
public class MainActivity extends AppCompatActivity{
would like to use more of a extends
how to do ?
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity implements SimpleOnScaleGestureListener {
private ImageView imageView;
private float scale = 1f;
@Override
public boolean onScale(ScaleGestureDetector detector) {
//Factor de zoom correspondente ao movimento feito
float scaleFactor = detector.getScaleFactor();
//Executa o zoom
performZoom(scaleFactor);
return true;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scaleGestureDetector = new ScaleGestureDetector(this,new MainActivity());
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.performClick();
//Chamar o onTouchEvent do nosso ScaleGestureDetector
scaleGestureDetector.onTouchEvent(event);
return true;
}
});
}
private void performZoom(float scaleFactor) {
scale *= scaleFactor;
scale = Math.max(0.1f, Math.min(scale, 5.0f));
imageView.setScaleX(scale);
imageView.setScaleY(scale);
}
}
Why do you need it?
– ramaral
@extension because of this
extends SimpleOnScaleGestureListener
– Vale
@ramaral what’s wrong I’m not managing to implement
– Vale
Implement the Listener interface and delegate the execution of methods to your implementation.
– utluiz
Simpleonscalegesturelistener is not a interface. Eliminate
implements SimpleOnScaleGestureListener
and declare a Inner class that extends of Simpleonscalegesturelistener that is to copy the class code Scalelistener of another answer into the Mainactivity– ramaral
Related, maybe duplicated: http://answall.com/q/22718/101
– Maniero
@ramaral the
view
would be who in the code ?– Vale
Is the Imageview where the zoom will be applied.
– ramaral
@ramaral but this
private ImageView imageView;
?– Vale
@ramaral went all right, but I wanted to ask a question, at the time you zoom in well zoomed in how to move the finger image to see the other part of the images ?
– Vale
Yeah, then things get complicated! Look at this reply
– ramaral