如何在android studio中显示多个图像视图

时间:2017-02-25 09:55:45

标签: android-studio imageview android-camera

我想显示从相机拍摄图像的多个图像视图。但是,我只知道如何显示1.任何人都知道如何显示多个图像视图?谢谢你的帮助!

public class ItemRegisterActivity extends AppCompatActivity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_item_register);
    this.imageView = (ImageView)this.findViewById(R.id.imageView1);
    imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, CAMERA_REQUEST);
        }
    });

}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(photo);
    }
}
}

其实我有这样的解决方案

public class ItemRegisterActivity extends AppCompatActivity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView1,imageView2,imageView3,imageView4;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_item_register);
    this.imageView1 = (ImageView)this.findViewById(R.id.imageView1);
    imageView1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, 1);
        }
    });
    this.imageView2 = (ImageView)this.findViewById(R.id.imageView2);
    imageView2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, 2);
        }
    });
    this.imageView3 = (ImageView)this.findViewById(R.id.imageView3);
    imageView3.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, 3);
        }
    });
    this.imageView4 = (ImageView)this.findViewById(R.id.imageView4);
    imageView4.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, 4);
        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView1.setImageBitmap(photo);
    }
    if (requestCode == 2 && resultCode == Activity.RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView2.setImageBitmap(photo);
    }
    if (requestCode == 3 && resultCode == Activity.RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView3.setImageBitmap(photo);
    }
    if (requestCode == 4 && resultCode == Activity.RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView4.setImageBitmap(photo);
    }
}
}

还有其他办法吗?必须使用回收视图?谢谢!

1 个答案:

答案 0 :(得分:0)

不幸的是,由于声誉较低,我无法发表评论。但是Here您可以看到如何使用多个图像视图实现RecyclerView。我希望它会对你有所帮助。