2

Possible Duplicate:
Android: Scale a Drawable or background image?

I want to set a drawable (from resources) as background of my view. But I want to stretch it only horizontally. How can I do this?

Community
  • 1
  • 1
Solvek
  • 5,158
  • 5
  • 41
  • 64

2 Answers2

2

There is no such scaleType that I can see. Have you tried this:

   <ImageView android:id="@+id/imageView"
      android:layout_width="fill_parent"
      android:layout_height="100dp"
      android:src="@drawable/image"
      android:scaleType="fitXY">
   </ImageView>

Then, you would need to place this in the background of another view, like making layers in a FrameLayout.

Lumis
  • 21,517
  • 8
  • 63
  • 67
1

The best way is to use 9-patch . It's strechable graphic.

Here is description of tool to creating 9-patch graphic.

Dennis Schröer
  • 2,392
  • 16
  • 46
pawelzieba
  • 16,082
  • 3
  • 46
  • 72
  • I tried. The problem with 9patch is that it changes paddings for my view. It is unwanted. – Solvek Mar 14 '11 at 17:47
  • 9patch sets a padding to view. If for example in xml padding was not set and I expect no padding my view has if I set 9patch as background to this view - it set paddings to somthing not 0. – Solvek Mar 14 '11 at 18:00
  • Have you tried 9patch without padding boxes (bottom and right black line)? – pawelzieba Mar 14 '11 at 18:05
  • Yes. In this case padding were set to 0, but for my view other value is spevified in layout, and I want this value. – Solvek Mar 14 '11 at 19:55