3

我正在开发一个应用程序,其中我需要通过检查条件随机更改四个​​图像。它适用于四个不同的值(例如:2,4,1,3),但如果我对四个图像使用五个值(例如:2,3,3,1,4)。然后,我无法识别两次更改图像的区别。

我正在使用以下代码。

                            if(id==0 || id==4) //here 0,4 appears sequencially then 
                                               // blue image not changed two times.

                               {
                                light1.setImageResource(R.drawable.blue_on);
                                light2.setImageResource(R.drawable.red_off);
                                light3.setImageResource(R.drawable.green_off);
                                light4.setImageResource(R.drawable.yellow_off);
                            }
                            else if(id==1 || id==5)
                            {
                                light1.setImageResource(R.drawable.blue_off);
                                light2.setImageResource(R.drawable.red_on);
                                light3.setImageResource(R.drawable.green_off);
                                light4.setImageResource(R.drawable.yellow_off);
                            }
                            else if(id==2 || id==6)
                            {
                                light1.setImageResource(R.drawable.blue_off);
                                light2.setImageResource(R.drawable.red_off);
                                light3.setImageResource(R.drawable.green_on);
                                light4.setImageResource(R.drawable.yellow_off);
                            }
                            else if(id==3 || id==7)
                            {
                                light1.setImageResource(R.drawable.blue_off);
                                light2.setImageResource(R.drawable.red_off);
                                light3.setImageResource(R.drawable.green_off);
                                light4.setImageResource(R.drawable.yellow_on);
                            }
4

2 回答 2

0

用这个

light1.setImageResource(getResources().getDrawable(R.drawable.ic_launcher));

安装的

light1.setImageResource(R.drawable.blue_off);
于 2013-04-19T10:17:30.403 回答
0

你可以使用TranslateAnimation来检测变化

您可以在View.StartAnimation中使用它

于 2013-04-19T10:18:53.917 回答