在onDoubleTapEvent上调整imageview的大小

时间:2010-11-17 12:32:50

标签: android resize imageview

我想在ImageView上调整doubleTapEvent的大小。代码示例将非常有用。

2 个答案:

答案 0 :(得分: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"
/>

爪哇:

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

像这样......

答案 1 :(得分:2)

以上代码无法正常运行img.setOnDoubleTapListener(this)行错误... 给出这种类型的错误 “方法setOnDoubleTapListener(this)是未定义的ImageView类型。”