emmanuel2004
emmanuel2004

Reputation: 127

Aspect ratio for bitmap

Im trying to make a drawable xml resource to use as background for an activity. The background need to have a image at the top and one at the bottom. My problem is that the images doesn't keep aspect ratio and get stretch by height. How do I make them keep aspect ratio?

The popup_activity_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_height="wrap_content"
                 android:layout_width="wrap_content">

<item>
   <layer-list>
        <item>
         <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
              android:src="@drawable/popup_header"
              android:tileMode="disabled"
              android:gravity="top" >
         </bitmap>
      </item>

      <item>
        <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
             android:src="@drawable/background_wizard"
             android:tileMode="disabled"
             android:gravity="bottom" >
        </bitmap>
      </item>
   </layer-list>
 </item>

I use the background for the root view in my activity layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:layout_marginTop="0dp"
android:windowActionBar="false"
tools:context="com.xxxx.xxxxx.PopupAddxxxxx"
android:orientation="horizontal"
android:background="@drawable/popup_activity_background">

Upvotes: 0

Views: 1410

Answers (1)

Pawan
Pawan

Reputation: 543

Try android:scaleType="fitXY" in your bitmap

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
  android:src="@drawable/background_wizard"
  android:tileMode="disabled"
  android:scaleType="fitXY">
</bitmap>

Disclaimer: Your image may look a bit blurry so try to 9Patch also.

Upvotes: 1

Related Questions