ImageView imageView = findViewById(R.id.myImageView); imageView.setMaxWidth(500);
ImageView imageView1 = new ImageView(this); imageView1.setImageResource(R.drawable.myImage); imageView1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); imageView1.setMaxWidth(250);This example creates a new ImageView object "imageView1", sets an image resource to it (the image must be saved in the "drawable" folder), and sets the maximum width to 250 pixels. It also sets the layout parameters of the ImageView to "wrap_content", which means that the width and height will adjust to the dimensions of the image. In both examples, the function "setMaxWidth" is called on an ImageView object, and the desired maximum width is passed as a parameter. The package library used in these examples is android.widget.