I am using myLinearLayout.setBackgroundResource(R.drawable.my_drawable) to set the background of a LinearLayout. Is there any way to maintain the source image's aspect ratio (zooming to fit when necessary) when using this method instead of having the image stretch to fit the LinearLayout?
xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/background_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
...
</LinearLayout>
java file:
backgroundLayout.setBackgroundResource(R.drawable.my_drawable);