Skip to content

Instantly share code, notes, and snippets.

@imminent
Created December 17, 2012 18:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imminent/4320447 to your computer and use it in GitHub Desktop.
Save imminent/4320447 to your computer and use it in GitHub Desktop.
set height ImageView stetches image to fit width while maintaining aspect ratio. Centers the stretched image in the window of the ImageView.
<ImageView
android:id="@+id/header_background"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignBottom="@+id/avatar"
android:paddingTop="8dp"
android:scaleType="centerCrop"
android:cropToPadding="true"
android:adjustViewBounds="true"
android:src="@drawable/anonymous_image_2"
android:contentDescription="user avatar" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment