ImageView imageView = findViewById(R.id.my_image_view); ViewGroup.LayoutParams params = imageView.getLayoutParams(); params.width = 200; params.height = 200; imageView.setLayoutParams(params);
ImageView imageView = new ImageView(context); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); imageView.setLayoutParams(params);This example creates a new ImageView programmatically, sets its layout parameters to wrap its content, and then applies the layout parameters to the ImageView. The ImageView class is part of the android.widget package library.