Android image scale type to fit width and scaleY = scaleX

androidandroid-layoutimageview

I have a layout with a background image. The image width should be the same as the screen width (match_parent). But it's ugly, the OS don't stretch the picture in height.
I heard about ImageView scaleType, so I have the background image in an ImageView instead of a layout background, but I can't config to be what I want.

How can I set to the layout or ImageView to scale the image (in width) to fit the width of the screen AND scale the height with the same scale?

I want the second screen in the picture:
enter image description here

UPDATE:

I'm trying from code, but I get 0 width + I can't believe this can't be done from xml with an ImageView.

    Drawable imageDrawable = getResources().getDrawable(imageResource);
    contentContainer.setBackgroundDrawable(imageDrawable);

    Rect rect = imageDrawable.getBounds();
    int originalWidth = rect.width();
    int originalHeight = rect.height();

    Display display = getActivity().getWindowManager().getDefaultDisplay(); 
    int width = display.getWidth();

    int height = originalHeight * (width/originalWidth);

    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height);
    contentContainer.setLayoutParams(layoutParams);


    contentContainer.post(new Runnable() {

        @Override
        public void run() {
            contentContainer.setScaleY(contentContainer.getScaleX());

            Rect rect = contentContainer.getBackground().getBounds();
            int originalWidth = rect.width();
            int originalHeight = rect.height();

            Display display = getActivity().getWindowManager().getDefaultDisplay(); 
            int width = display.getWidth();

            int height = originalHeight * (width/originalWidth);

            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height);
            contentContainer.setLayoutParams(layoutParams);

        }
    }

Best Answer

Use FrameLayout as parent and then add imageview as child.