2010-11-17 87 views

回答

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)); 
    } 

事情是這樣的......

+0

感謝它爲我工作。現在我想給doubleTapEvent放大和縮小效果。再次感謝 – Zoombie 2010-11-18 06:20:58

+0

@Zoombie你確定這適用於你:D – 2013-12-13 10:07:21

+1

這是錯誤的**答案**你不能在'ImageView'上設置onDoubleTapListener – 2013-12-13 10:08:51

2

上面的代碼是不工作的img.setOnDoubleTapListener給出錯誤(這)行... 給出這種類型的錯誤 「方法setOnDoubleTapListener(this)是未定義的類型ImageView」。

+1

複製粘貼你的代碼在這裏。 – Zoombie 2012-09-28 05:34:26

+0

我同意@Hemant Vc – 2013-12-13 10:12:07