Skip to content

Instantly share code, notes, and snippets.

@rajohns08
Last active November 3, 2015 13:16
Show Gist options
  • Save rajohns08/04346e93e0c5cffc6e47 to your computer and use it in GitHub Desktop.
Save rajohns08/04346e93e0c5cffc6e47 to your computer and use it in GitHub Desktop.
Android - Skeleton layout for using a background image for a layout while maintaining the image's aspect ratio
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/background_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/your_drawable"/>
<LinearLayout
android:id="@+id/your_actual_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</FrameLayout>
// later if you want to change bg image in code
backgroundImageView.setImageResource(R.drawable.your_drawable);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment