Use the same filename for each of the different versions, and then when you specify the drawable name, the Android resources manager will choose the image from the appropriate folder. These represent the increasing resolutions of each device, and appropriately sized images should be placed in each. Typically, you will create four different versions of each image and place them in the following folders: drawable-ldpi, drawable-mdpi, drawable-hdpi, and drawable-xhdpi. These folders follow the device-configuration naming scheme to provide different images for different devices. Images used in your application are stored in the /res/drawable folders. Bottom row (l-r): fitCenter, fitStart, fitEnd, fitXY. Top row (l-r) center, centerCrop, centerInside. A Matrix class can be used to apply transformations such as rotations to an image.įigure 4.9 Examples of android:scaleType attribute. The matrix can be supplied using the setImageMatrix method. Scales the image using a supplied Matrix class. Scales the x and y dimensions to exactly match the view size does not maintain the image aspect ratio. Same as fitCenter but aligned to the bottom right of the view. Same as fitCenter but aligned to the top left of the view. At least one axis will exactly match the view, and the result is centered inside the view. Scales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center. Scales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio crops any part of the image that exceeds the size of the view centers the image in the view. Table 4.1 ImageView Scale Typesĭisplays the image centered in the view with no scaling. Table 4.1 lists the scale type options and how they alter the image. Other scaling options fit the image to the dimensions of the image view or scale the image based on the width and height of the device. In the example, using scale type center, the image will be displayed at its native resolution and centered in the view, regardless of how much space the view consumes. Note the scaleType attribute? This defines how the images will be scaled to fit in your layout. The ImageView handles all the loading and scaling of the image for you. This example will display an image named “icon”: Image resources are placed in the /res/drawable folders. The simplest way to display an image is to declare an ImageView in your layout file and set its source to a resource in your project. Unless you need special optimizations for your application, you should take advantage of the built-in image view whenever possible. This view takes care of the loading and optimizing of the image, freeing you to focus on app-specific details like the layout and content. Typically, images are displayed using the built-in image view. Images are an important way of conveying information to your users without explicitly stating it. Android UI Fundamentals: Develop & DesignĪndroid phones feature large, high-resolution displays that are perfect for displaying images in your application.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |