2010-11-17 4 views

Répondre

3

XML:

<?xml version="1.0" encoding="utf-8"?> 
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/myImage" 
android:src="@drawable/myPicture" 
android:layout_width="64sp" 
android:layout_height="64sp" 
/> 

Java:

public class MyActivity extends Activity implements OnDoubleTapListener{ 
    private ImageView img; 

    private static int NEW_WIDTH = 100; 
    private static int NEW_HEIGHT = 100; 

    @Override 
    public void onCreate(Bundle savedInstanceState){ 
     setContentView(R.layout.myLayout); 
     this.img = findViewById(R.id.myImage); 
     img.setOnDoubleTapListener(this); 
    } 

    public boolean onDoubleTap(MotionEvent e){ 
     this.img.setLayoutParams(new LayoutParams(NEW_WIDTH, NEW_HEIGHT)); 
    } 

Quelque chose comme ça ...

+0

Merci cela a fonctionné pour moi. Maintenant, je veux donner un effet de zoom avant et de zoom arrière sur doubleTapEvent. Merci encore – Zoombie

+0

@Zoombie Etes-vous sûr que cela fonctionne pour vous: D –

+1

C'est faux ** Réponse ** vous ne pouvez pas définir onDoubleTapListener sur 'ImageView' –

2

code ci-dessus ne fonctionne pas donner erreur sur la ligne img.setOnDoubleTapListener (this) ... donne ce type d'erreur "La méthode setOnDoubleTapListener (this) est la non définie pour le type ImageView".

+1

copier coller votre code ici. – Zoombie

+0

Je suis d'accord avec @Hemant Vc –