How do I add an image in the drawable folder to an ImageView in Android Studio 1.2?

41,263

Solution 1

try with this way of code there are three ways to set image on ImageView

imageView.setImageResource(R.drawable.play);

or

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

or

              <ImageView
              android:id="@+id/ivProfileBg"
              android:background="@drawable/image_name"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />

Solution 2

Paste the PNG image in the following directory <Project-Name>\app\src\main\res\drawable\ (if the drawable directory doesn't exist, create a new one).

now add the src attribute to the imageView like i done.

           <ImageView
                android:id="@+id/ivProfileBg"

                android:src="@drawable/image_name"

                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

where the image_name is the name of the PNG image you just pasted into the drawable directory.

if you wanted to paste the image into the hdpi section, you must create the directory under res\ folder, then the path would be <Project-Name>\app\src\main\res\drawable-hdpi\

Share:
41,263
Justin M.
Author by

Justin M.

Updated on October 14, 2020

Comments

  • Justin M.
    Justin M. over 3 years

    Since Google added the mipmap folder for the launcher icons, I have had issues using the drawables folder. I manually added the hdpi folders in the drawable folder, but when I try and add the src path, the images won't allow me to view and select them. How do I add an image in the drawable folder to an ImageView in Android Studio 1.2?

  • Justin M.
    Justin M. about 9 years
    I already have the folders, but I cannot access what is within them.
  • Justin M.
    Justin M. about 9 years
    It gives me an error saying that it Couldn't resolve resource @drawable/main_title