Image in android

To display an image in an Android app, you can use an ImageView element in your layout file, and set the src attribute to the resource ID of the image you want to display.

Here’s an example of how you might include an ImageView element in an XML layout file:

<ImageView
    android:id="@+id/image_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/my_image" />

You can also set the image programmatically, by using the setImageResource method of the ImageView object:

ImageView imageView = findViewById(R.id.image_view);
imageView.setImageResource(R.drawable.my_image);

In both of these examples, my_image refers to an image file that is stored in the res/drawable directory of your project.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *