Reputation: 818
I got a picture that I want to use. I set it as following:
ImageView menu = new ImageView(this);
menu.setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT));
menu.setImageResource(R.drawable.menu);
They annoying thing is that I get white pixels on the sides of it cause I want to keep the aspect of the pic.
I can stretch the image by using menu.setScaleType(ScaleType.FIT_XY);
but that will make the person on it look really fat. The picture is dark and the pixels are white so they do show quite well. :/
Is there I way I can first apply black color and then the image above that color?
Upvotes: 1
Views: 816
Reputation: 607
To set a background color to any view on android you can use android:background
attribute in layout xml or by calling setBackgroundColor(int id)
in java code.
But if you really want just to set the image in bounds you can give a try to android:scaletype="centerCrop"
Upvotes: 1
Reputation: 17
Using set BackgroundColor will also remove any padding, borders and what not attached to the object. If that is the result you want, that is a reasonable approach. If blasting the objects current style will cause problems, I would look to use CSS to set the background color and change the css styles through code if things are happening after page load. Consider using a border around the image that is colored the way you want to hide what is underneath?
Upvotes: 0