0

每次用户触摸屏幕时,我都想更改图像。我想让用户点击屏幕,图像每次都会改变,在第 5 次触摸时,它会循环回到带有添加文本的原始图像。

我看过

我如何将 ImageButton 设置为仅在我的手指触摸它时才更改

我已经尝试过 IUevents 和 StateListdrawable。我无法弄清楚每次触摸后如何实际更改图像(屏幕中的任何位置)。

4

2 回答 2

1

为什么不能使用普通的ImageView?做这个:

ArrayList<Integer> picList = new ArrayList<Integer>(); 
// populate the list with the int value of the pictures in drawable.
picList.add(R.drawable.apple);
picList.add(R.drawable.horse);
//etc
int touches = 0;
int loop = 0;
ImageView picture = (ImageView) findViewById(R.id.your_picture);
picture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
           if (touches < 4)
                v.setBackgroundDrawable(picList.get(touches));
                touches++;
           } else {
                touches = 0;
                loop = 1;
                v.setBackgroundDrawable(picList.get(touches));
           }
           if (loop = 1){
           // Create a TextView and set the text or make it in the xml with Visible="Gone" and make is visible here.
           }
    });
于 2011-09-23T07:27:18.530 回答
1

您需要创建扩展 ImageView 的自定义类现在将此图像视图显示到整个屏幕。

> First store the path/location of images into an array/list etc.
> In custom class implement the onTouch event.
> create the counter object in this custom class.
> now in onTouch check in down event that check the counter value with array size if counter==array.length()-1 then set counter as 0 otherwise increment in counter object.
> now get the path of the image and set into the imageview as background
于 2011-09-23T07:07:01.663 回答