Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Imageview上的触摸事件_Android - Fatal编程技术网

Android Imageview上的触摸事件

Android Imageview上的触摸事件,android,Android,我正在创建一个android应用程序。 这里我有一个图像视图。 我的目标是在移动手指时从数据库中获取下一张图片 float nPicturePositionM = 0; public boolean onTouch(View v, MotionEvent event) { boolean aHandledL = false; if (event.getAction() == MotionEvent.ACTION_MOVE) { float nNewPicture

我正在创建一个android应用程序。 这里我有一个图像视图。 我的目标是在移动手指时从数据库中获取下一张图片

float nPicturePositionM = 0;

public boolean onTouch(View v, MotionEvent event) {
    boolean aHandledL = false;
    if (event.getAction() == MotionEvent.ACTION_MOVE) {
        float nNewPicturePosL = event.getX();
        if (nPicturePositionM < nNewPicturePosL) {
            nPicturePositionM = nNewPicturePosL;
            GetPictures(true);
        } else {
            nPicturePositionM = nNewPicturePosL;
            GetPictures(false);
        }
        aHandledL = true;
    }

    return aHandledL;

    //return false;
}
float-nPicturePositionM=0;
公共布尔onTouch(视图v,运动事件){
布尔值aHandledL=false;
if(event.getAction()==MotionEvent.ACTION\u MOVE){
float nNewPicturePosL=event.getX();
如果(nPicturePositionM

我如何使用触摸事件处理它?图像应该像在gallery中那样滑动

首先,您要在xml中声明一个imageview:

<ImageView
    android:id="@+id/imageview1"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="45dp"
    android:layout_centerHorizontal="true" />
下一步是检测图像是否被“点击”。然后,您可以使用在线数据库或SQLite数据库来保存图像或图像路径,其中的数据库部分是一个很大的部分,需要从头开始教授,具体取决于您希望采用的路线:

       this.image1.setOnClickListener(new View.OnClickListener() {        
        @Override
           public void onClick(View view) {
            if (view == findViewById(R.id.imageview1)) {     
                         //PUT IN CODE HERE TO GET NEXT IMAGE
            }
            }
        });

我希望这有帮助。让我知道它是如何运行的:)

你必须使用数据库中的图像数组,并在触摸的基础上进行设置……比如

img.setOnTouchListener(new OnTouchListener() 
        {

            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) 
            {
                    img.setImageURI(uri[pos]);
                    pos++;
                    return false;
            }
        });

我如何使用触摸事件处理它?图像应该像在gallerysure中那样滑动。使用setOnTouchListener而不是SetOnClickListener我使用setOnTouchListener并移动图像,但速度太慢,它会跳过中间的图像。我已经在上面提供了我的代码。你能看一下这里面有什么问题吗?我怎么解决呢?我不太确定,可能跟刷新率有关。我会研究一下,然后再联系你。我想得到下一张图片,并根据左右滑动预览图片。你能帮我解决这个问题吗?
img.setOnTouchListener(new OnTouchListener() 
        {

            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) 
            {
                    img.setImageURI(uri[pos]);
                    pos++;
                    return false;
            }
        });