title: Displaying part of a spritesheet in an Android ImageView
body: <p>In Android, is there a <strong>clean</strong> way to display only a given part of a bitmap in an ImageView (for example a single sprite of a sprite sheet), without having to :</p>
  
  <ul>
  <li>Manually split the bitmap png into small pngs (=> more drawables embedded in the app, tedious manual operation possibly leading to bugs, or loose the spritesheet).</li>
  <li>Have small pngs used in the ImageViews, with the sprite sheet being generated (=> complicated) </li>
  <li>Create "dirty" subclasses for ImageView, Drawable, etc (=> the more we use Android API "ASIS" the better)</li>
  <li>Programmatically create sub-bitmaps of the big bitmap (=> We have to do all the work programmatically)</li>
  </ul>
  
  <p>For instance I have tried creating an ImageView of width/height of 40dp, and setting its drawable as a ClipDrawable displaying only the part of the bitmap I wanted, but it did not go well :</p>
  
  <ul>
  <li><p>the clipped part did not fill the parent when using Gravity.CENTER when creating the ClipDrawable. </p></li>
  <li><p>The whole "big" PNG was displayed when using Gravity.FILL. </p></li>
  </ul>
  
  <p>Furthermore this solution is feasable with a simple sprite sheet (for example 2*2 sprites), but I do not think it is possible when using something like a 4*4 sprite sheet. I think ClipDrawable is not meant for such a use.</p>
  
  <p>Isn't there something "clean and easy" like in OpenGL where you can set a texture Id, and set the texture coordinates to display only part of the texture? Considering my researchs I think the best solution is to manually split the big bitmap with Bitmap.createBitmap, when I'd rather ask before starting something like that.</p>
  
  <p>PS : I consider using SpriteSheets because of OpenGl, although my "menus" are developed using Android APIs, hence using ImageView.</p>