我为imageView编写了一个onTouchListner(),如下所示:

        final ImageView image = (ImageView) findViewById(R.id.but_kh);
        final ImageView hover = (ImageView) findViewById(R.id.hov_but);
        image.setOnTouchListener(new  OnTouchListener() {

            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                image.setVisibility(0);
                hover.setVisibility(100);
                return false;
            }
        });


如您所见,我将图像的可见性设置为0,但是当图像的悬停完成时我不知道如何将其设置为100,这意味着我想在悬停后更改这两个图像的可见性:

                image.setVisibility(100);
                hover.setVisibility(0);


提前致谢,

最佳答案

image.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()){
            case MotionEvent.ACTION_DOWN:
                                     image.setVisibility(0);
                                     hover.setVisibility(100);
                break;
            case MotionEvent.ACTION_UP:
                                     image.setVisibility(100);
                                     hover.setVisibility(0);
                break;
            }
            return true;
        }
    });

10-08 15:19