3

I'm trying to get my imageview with a drawable png to fill the display (I don't care about ratios). However, fill_parent doesn't work, and as far as I know there are no background to be set to a RelativeLayout?

Regards

RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:onClick="toggleAdvice"



   ImageView
    android:id="@+id/advice_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/pratbubbla_gron"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
Carl Manaster
  • 39,912
  • 17
  • 102
  • 155
elwis
  • 1,395
  • 2
  • 20
  • 34

3 Answers3

8

All View types have android:background, including RelativeLayout. No need for an ImageView, although I can't see any reason for your one to not fill the parent.

Reuben Scratton
  • 38,595
  • 9
  • 77
  • 86
8

I used to stretch/shring ImageView programmatically, probably this piece of code will help you:

    ImageView imageView=new ImageView(context);
    imageView.setAdjustViewBounds(true);
    imageView.setImageBitmap(bitmap);
    imageView.setMaxHeight(maxHeight);
    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    layout.addView(imageView);
Barmaley
  • 16,638
  • 18
  • 73
  • 146
1

to do it in code use: yourImageView.setScaleType(ImageView.ScaleType.FIT_XY);

Bobby
  • 6,115
  • 4
  • 35
  • 36