1

我为 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);

提前致谢,

4

1 回答 1

2
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;
        }
    });
于 2013-09-13T15:11:14.623 回答