How To Set Image In Imageview?
I need to put my own image on some imageView. So that's why I created folder named 'drawable' in res folder , and copy my Image in this folder , but now I don't know how to set thi
Solution 1:
In your layout XML file:
<ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/your_image_name"/>
Replace your_image_name
with the name of the image file without the extension (e.g. if your drawable file is called img1.png
, the src
attribute should have a value of @drawable/img1
).
Solution 2:
Set it using android:src=""
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image_name" />
Solution 3:
Try this.
<ImageView
android:id="@+id/YourImageViewID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/Your_Image_Name"
/>
This may help you.
Solution 4:
//set background as your image by calling the android:background
attributes in your xml
<ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/myimage"
/>
Note: you no need to create any drawable folder by default android project will contain
drawable-mdpi
drawable-hdpi
drawable-ldpi
you can put your image in that.
Post a Comment for "How To Set Image In Imageview?"