0

I'm wondering if it's possible to align the background of a View in android. I have an image as a BitmapDrawable that I would like to fill and align it's right edge with the View.

I was using the Gravity.CENTER value in order to keep the background's contents centered, but now I need to have the image as the background, but align its right edge to the View's right edge, while still filling the entirety of the View, cropping the extra.

Is this possible?

EDIT:

Oops. The "What have I tried?" part is missing.

I've tried setting the gravity to Gravity.RIGHT, but that just ended up centering and shrinking the background.

Setting (Gravity.CENTER | Gravity.RIGHT) also had the same results.

I've tried looking on google, but it only spoke of using an ImageView, but I need to have Views in this View.

So, thats what I've tried and I don't know what else to do.

EDIT 2:

To be clear, I'm talking about this

RileyE
  • 10,874
  • 13
  • 63
  • 106
  • Are you talking specifically of an `ImageView`? Or any `View` object? I had done something similar for ImageViews that I may be able to help with but doubt it would work on other View objects. – Grambot Mar 13 '13 at 20:44
  • @TheCapn I know how to do it with an `ImageView`, but I'm talking about the `background` property of a `View`. Thanks, though! – RileyE Mar 13 '13 at 20:51
  • 1
    Well my solution wouldn't work then. I had used a `LayerDrawable` to remove the need for a background and provided me a means to control the `BitmapDrawable`'s bounds. Perhaps this link will help you however: http://stackoverflow.com/a/2782035/804773 – Grambot Mar 13 '13 at 21:03
  • @TheCapn That's odd. Thats what I'm doing, but in Java code. Its not an image in my bundle, but rather a dynamic image, so I can't use XML quite the same way. However, thats a great find. I wonder why it doesn't work for me.. – RileyE Mar 13 '13 at 21:05

0 Answers0