elwis
elwis

Reputation: 1405

android, imageview stretch

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"

Upvotes: 3

Views: 9816

Answers (3)

Bobby
Bobby

Reputation: 6255

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

Upvotes: 1

Barmaley
Barmaley

Reputation: 16363

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);

Upvotes: 8

Reuben Scratton
Reuben Scratton

Reputation: 38707

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.

Upvotes: 8

Related Questions