如何在android中对图像数组中的每个图像执行操作

如何在android中对图像数组中的每个图像执行操作,android,android-layout,Android,Android Layout,嗨,在我的应用程序中,我需要在3行和2列中显示6幅图像。我需要在每个图像上执行操作。但我只能在前三个图像上执行操作。我如何在6个图像上执行操作 TableLayout.LayoutParams param,param1; ImageView[] plus=new ImageView[6]; TableRow[] row = new TableRow[6]; RelativeLayout.LayoutParams lp2,lp1,lp3,lp4,lp5;

嗨,在我的应用程序中,我需要在3行和2列中显示6幅图像。我需要在每个图像上执行操作。但我只能在前三个图像上执行操作。我如何在6个图像上执行操作

  TableLayout.LayoutParams param,param1;

    ImageView[] plus=new ImageView[6];
     TableRow[] row = new TableRow[6];

      RelativeLayout.LayoutParams lp2,lp1,lp3,lp4,lp5;
      RelativeLayout linear;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main1);


         layout = new TableLayout (this);
         layout.setLayoutParams( new TableLayout.LayoutParams(40,50) );
         param=new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,TableLayout.LayoutParams.WRAP_CONTENT);
         param.setMargins(25, 0, 0, 0);
         lp1=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
         linear=(RelativeLayout)findViewById(R.id.linear);
         Collections.shuffle(solutionList);

         randomNumbers = (Integer[])solutionList.toArray();

         int unique=0;

         for (f=0; f<3; f++) {
             row[f] = new TableRow(this);
             for (int c=0; c<2; c++) {

                 plus[f]=new ImageView(this);

                 plus[f].setBackgroundResource(randomNumbers[unique]);



                 plus[f].setOnClickListener(this);

                 row[f].addView(plus[f], 200,100);

                 unique++;
             } // for
             layout.addView(row[f],param);
         } // for

         linear.addView(layout,lp1);

         setContentView(linear);
        image1=new ImageView(this);
         image1.setBackgroundResource(R.drawable.pennib);

         lp2=new RelativeLayout.LayoutParams(200,100);
         lp2.setMargins(230, 0, 0, 0);
         linear.addView(image1,lp2);

              image1.setOnClickListener(new View.OnClickListener() {
           public void onClick(View view) {

               Log.i("",""+i);
            if (isFirstImage) {       
             applyRotation(0, 90);
             isFirstImage = !isFirstImage;

            } else {    
             applyRotation(0, -90);
             isFirstImage = !isFirstImage;
            }

           }
        });    



        }

        private void applyRotation(float start, float end) {
        // Find the center of image
        final float centerX = image1.getWidth() / 2.0f;
        final float centerY = image1.getHeight() / 2.0f;

        // Create a new 3D rotation with the supplied parameter
        // The animation listener is used to trigger the next animation
        final Flip3dAnimation rotation =
               new Flip3dAnimation(start, end, centerX, centerY);
        rotation.setDuration(500);
        rotation.setFillAfter(true);
        rotation.setInterpolator(new AccelerateInterpolator());
        rotation.setAnimationListener(new DisplayNextView(isFirstImage, image1,plus[0] ));

        if (isFirstImage)
        {
        image1.startAnimation(rotation);
        } else {
            plus[0].startAnimation(rotation);
        }
    }



        }
TableLayout.layoutparms param,param1;
ImageView[]plus=新的ImageView[6];
TableRow[]行=新TableRow[6];
RelativeLayout.LayoutParams lp2、lp1、lp3、lp4、lp5;
相对线性;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
布局=新的表格布局(本);
layout.setLayoutParams(新的TableLayout.LayoutParams(40,50));
param=新建TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_内容,TableLayout.LayoutParams.WRAP_内容);
参数设置边距(25,0,0,0);
lp1=新的RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_内容,RelativeLayout.LayoutParams.WRAP_内容);
线性=(相对长度)findViewById(R.id.linear);
集合。洗牌(解决方案列表);
randomNumbers=(整数[])solutionList.toArray();
int unique=0;

对于(f=0;f请改用gridview,并使用gridview.setonItemClich listener这是解决您的问题的最简单和优化的解决方案。如果您需要gridview方面的帮助,请告诉我


祝你有愉快的一天!!

好吧,当你有这样的for循环时,你不能有plus[3]

 for (f=0; f<3; f++) {
         row[f] = new TableRow(this);
         for (int c=0; c<2; c++) {

             plus[f]=new ImageView(this);

             plus[f].setBackgroundResource(randomNumbers[unique]);



             plus[f].setOnClickListener(this);

             row[f].addView(plus[f], 200,100);

             unique++;
         } // for
         layout.addView(row[f],param);
     } // for

for(f=0;fi)尝试了网格视图,但如果我在网格视图上应用随机函数,则图像会重复。我将int f=0表示为全局。但如果我将列值表示为c,则只能得到2