views:

412

answers:

1

I'd like to use a small (icon size) image as the background for my view, but it gets stretched to fill all the view.

Any solution (including some way to place a view under my current one and make the latter transparent) will be appreciated.

Thanks !

current code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
  android:background="android:background="@drawable/icon"
  android:id="@+id/layout_main"
 >
+1  A: 

You have two choices:

  1. Make the image bigger. Specifically, add a single black line all around its edges, then use the tools/draw9patch tool to make that black line the 'stretchable' part. When the image is scaled up to the background, your original icon will not be stretched.

  2. Give up on the android:background and use a top level RelativeLayout instead. This should work

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageSwitcher
        android:id="@+id/ImageSwitcher01"
        android:layout_width="wrap_content"
        android:layout_centerInParent="true"
        android:layout_height="wrap_content"
        android:background="@drawable/icon">
    </ImageSwitcher>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">
        <TextView
            android:text="Your old top level here"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content">
        </TextView>
    </LinearLayout>
</RelativeLayout>

Hope this helps

Charles Merriam