3

How do I set the android:scaletype attribute for the background image of a RelativeLayout? The XML code is below:

<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:background="@drawable/background"
    android:gravity="center_vertical"
    tools:context=".MainActivity" >
vergil corleone
  • 1,091
  • 3
  • 16
  • 34
  • you cannot set scaletype for relative layout background image instead you can place image view with same width and height of the relative layout and set scale type for the image view – KMI Jan 11 '14 at 09:17
  • KMI: Ok. Where should I put the ImageView? Inside relative layout? – vergil corleone Jan 11 '14 at 09:28
  • yes put inside the relative layout – KMI Jan 11 '14 at 09:29
  • May i know ? why you want to use the scale type for relative layout background image? – KMI Jan 11 '14 at 09:33
  • 1
    The background image is long lengthwise so I want to crop out the extra length of the image and only show the amount of image that fits into the phone's resolution. Also KMI, there are other things in my relativelayout so how do I keep the new ImageView with the background at the back and the other buttons etc on the front of the screen? – vergil corleone Jan 11 '14 at 10:30
  • possible duplicate of [Android: Scale a Drawable or background image?](http://stackoverflow.com/questions/1400782/android-scale-a-drawable-or-background-image) – gnuf Apr 16 '15 at 18:21

0 Answers0