Обновление: я решил эту проблему, используя метод, описанный в этом ответе
Я немного застрял в этом вопросе, который, я думаю, должен быть довольно простым.
Итак, мое приложение загружает изображение и отображает растровое изображение в ImageView, дочернем элементе RelativeLayout. Я бы хотел, чтобы ImageView соответствовал ширине родительского элемента и адаптировал его размер, чтобы сохранить соотношение сторон.
Вот мой XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout android:id="@+id/banner" android:layout_width="fill_parent" android:layout_height="wrap_content"></RelativeLayout>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello"
/>
</LinearLayout>
И код:
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    RelativeLayout banner = (RelativeLayout) findViewById(R.id.banner);
    ImageView imgV = new ImageView(this);
    imgV.setScaleType(ImageView.ScaleType.CENTER_CROP);
    // I tried all the scale types : CENTER_INSIDE : same effect, FIT_CENTER : same effect... 
    imgV.setBackgroundColor(0x00FFFF00);
    imgV.setAdjustViewBounds(Color.BLUE);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    banner.addView(imgV,params);
    // Some code downloading the image stream
    bitmap = BitmapFactory.decodeStream(stream);
    imgV.setImageBitmap(bitmap);
    }
Желаемый:
 
Результат:
 
