Resize imageview on onDoubleTapEvent

落爺英雄遲暮 提交于 2019-12-08 04:46:47

问题


I want to resize an ImageView on doubleTapEvent. A code example will be really helpful.


回答1:


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

Something like this...




回答2:


Above code is not working give error on img.setOnDoubleTapListener(this) line ... give such type of error "The method setOnDoubleTapListener(this) is the undefined for the type ImageView".



来源:https://stackoverflow.com/questions/4204373/resize-imageview-on-ondoubletapevent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!