Is it possible to set a background png on a view and anchor it to the top and not scale in Android?

StackOverflow https://stackoverflow.com/questions/1320421

Question

I have an image, say 16px from our designer. I want to set it as the background image on a view, but the view is larger than the image. So, I want to anchor the image at the top of the view, and then have the view fill in the bottom with a solid color.

Is this possible in the current version of Android, 1.5_r3?

Here is what I have so far:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="3dip"
style="@style/listItemStyle">...

Where listItemStyle is defined as:

 <style
  name="listItemStyle"
  parent="@android:style/Widget.ListView">
   <item name="android:background">@drawable/list_background</item>
 </style>

But the image is scaling to take up the entire view, and I am not sure how to set the image as the background and specify a solid color at the same time. I suspect I need to wrap the view in a containing view which has the color specified, is that the best way to do it?

Was it helpful?

Solution

Place your image in a ImageView, and then use the solid color as a background of the item view. This is one alternative.

Cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top