How to add image to dropdown folder in ImageView in Android Studio 1.2?

Since google added a mipmap folder for launcher icons, I had problems using the drawables folder. I have manually added hdpi folders to the portable folder, but when I try to add the src path, the images won't let me browse and select them. How to add image to dropdown folder in ImageView in Android Studio 1.2?

+3


source to share


5 answers


try with this code way there are three ways to set image in 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" />

      

+3


source


Paste the PNG image into the following directory <Project-Name>\app\src\main\res\drawable\

(if the dropdown directory doesn't exist, create a new one).

now add the src attribute to the imageView as i did.

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

                android:src="@drawable/image_name"

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

      



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

if you want to insert image in hdpi section you have to create a directory in folder res\

then path will be<Project-Name>\app\src\main\res\drawable-hdpi\

+1


source


In the upper left corner of the screen, right below the Project title, there is an overview of the project (directories, files, etc.) to change from "Android" to "Project". then go to / app / src / main / res. then right click on res and create a folder to move inside! Put your case there. you can access the resource using: @drawable / ... internally when you are going to use it.

0


source


Adding an hdpi folder inside an accessible folder won't work because it won't be detected by android. For easier navigation, you can switch and view the Project Explorer from Android "to Project " as shown below:

enter image description here

In the project view, you can view all available folders including hdpi, mdpi, etc., for example the following path: src app / src / main / res / ...

enter image description here:

0


source


It turns out I need not to create subfolders of hdpi folders. Android Studio will automatically categorize them in a portable folder. Thank you for your help!

0


source







All Articles