![]() ![]() As a matter fact, there are multiple ways to accomplish this:ġ. Loading an image from the assets folder is handled differently than loading one from the drawable folder. Right-click on main will allow you to create a new Directory called "assets" folder of your application using command line and then issue a mkdir assets command or change the "Android" view to 'Project" view in Android Studio and navigate to app/src/main. ![]() By default, this folder isn't created by Android Studio when your project is created so you will need to create it yourself. Another common place to put files is the assets folder (a subfolder of main). You can also use images that are stored in places other than the resources > drawable folders. ![]() tImageResource(R.drawable.pic2)Īlthough using the res > drawable folder is preferred because it takes advantage of the operating system's resource management system, when it comes to using files in your app's resources folders, you have several options. To programmatically set the image source to an image stored in your drawable folder, you use setImageResource(), which takes a resource id argument: val imageView: ImageView = findViewById(R.id.imageView) The " android:src" attribute of the ImageView should point to a file in your res > drawable folders. You can specify the height, width, gravity, etc, just like any other View. ![]() To display an image in your app, simply add an ImageView to you layout file. For this lesson, download the following archive of images (or feel free to use your own.just make sure you get the correct names): Additionally, there are other views, like a Gallery, that let us get even more creative with our images. By using the provided ImageView, you can add images anywhere in your layout. Let's do that! Incorporating images is simple. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |