..
The ImageView is none other than the object that allows the programmer to show the screen image. Prior to making a practical example of a display on the ImageView is necessary to understand where to put our image and understand the structure of the res folder of our project.
Going to explore their own will find this folder a subfolder layout, which we used thoroughly up to date, and three other sub-folders identified by the following names:
Subfolders listed above are those that will contain the images that we want to put in our application.
But what is the meaning of these folders? So given that Android is a mobile operating system that is installed on different devices with different risoluzone to have some sort of image enhancement should create three versions of the images in different sizes. These three versions of the images should be placed in order of size from largest to smallest in the folders above views.
Of course, to display an image on the screen is sufficient that there is at least one version of the image in one of three folders. In the event that we wanted to show an image optimized for display on low risuluzione high-resolution screens we have to enlarge the image resulting in an inevitable blurring of the image.
Having said that we provide a practical example. Take a sample image and put this folder in the views above (also avoiding the creation of three versions of the image). Without this you must open the file main.xml and insert the code for the declaration of our ImageView we called Image:
<ImageView android: id = "@ + id / Image" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"> </ ImageView>
Now open the file. ImageView object and import java
android.widget.ImageViewdeclare an object of type ImageView
private ImageView miaImmagine;and then insert the following code:
miaImmagine = (ImageView) findViewById (R.id.Image); miaImmagine.setImageResource (R.drawable.ImmagineEsempio);
As we can see the code for the display of an image is very simple. In the first line we associate the XML element declared with that stated in the code and set the value of the image followed by the method setImageResource. Next is the code for this method to our image files that are in the R-class seat in the drawable.
How inutuibile understand, when we insert any image in a folder-drawable ... automatically creates a constant for the image files in the sub-class R drawable. The name used in the example, ImmagineEsempio, is the name for the file that identifies the image. As we can see you just enter just the name of the file omitting the extension.
A special feature of Android is to perform an automatic image resize larger than the screen resolution. To see this behavior is sufficient to show a screen image in high risuluzione. This will be resized, in a completely automatic, and adapted to the screen of the simulator or the device without problems. The resize an image from biggest to smallest involves no loss of quality (increase is, however, operations that are performed by the operating system when the application should be launched) vice versa, as we said earlier, there would be a loss of quality proportional to the magnification.
| |
Excel (Ebook)
Create spreadsheets and calculation. Just 25 €. |
| |
MS Access (Advanced)
Learn how to create and manage databases quickly and easily. Starting from 29 €. |
| |
Web Design (Course)
Design Web Sites with HTML, CSS and Dynamic HTML. From 39 €. |