Pages

Wednesday, January 15, 2014

ImageView ScaleTypes

When there are images that need to be displayed in an Android app, we need to be careful with the way they are scaled. A first basic step is setting the right scaletype in your layout file.

The different scaletypes are:

  • center
  • centerInside
  • centerCrop
  • fitXY
  • fitStart
  • fitCenter (which is the default)
  • fitEnd
  • matrix (can be used for transformations but is not covered here)


This post will just simple show the different scaletypes with a screenshot of how it looks in the app.
Here's the code of my layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/logo"
        android:scaleType="centerCrop" />

</RelativeLayout>

Image larger than its given space


center
centerInside
centerCrop
fitXY
fitStart
fitCenter (default)

fitEnd

Image smaller than its given space



center
centerInside
centerCrop
fitXY
fitStart

fitCenter

fitEnd

6 comments:

  1. This is amazing, thanks for the share. Also, check this out if you are looking for professional website or logo design services:


    Buy Logo

    ReplyDelete
  2. First I want to tell you that. Thank you for sharing it with us.
    I am really happy and impressed to see this blog!
    law essay writing help

    ReplyDelete
  3. I feel satisfied with your share. It's very helpful for me and I am so happy to see your blog. Thank you for sharing it with us. If you are looking law dissertation help ​Then Visit our site we are giving you 5O& off.

    ReplyDelete
  4. very nice… I really like your blog. Really very happy to say, your post is very interesting to read. I never stop myself to say anything about it. You’re doing a great job. Keep it up.This Blog is interesting and please checkout for more information Trolley Bay Kits in Australia.

    ReplyDelete
  5. very nice… I really like your blog. Really very happy to say, your post is very interesting to read. I never stop myself to say anything about it. You’re doing a great job. Keep it up.This Blog is interesting and please checkout for more information Magento Development.

    ReplyDelete