Skip to content Skip to sidebar Skip to footer

How To Scale Small Imageview To Fill Large Scrollview?

How do you create a layout with a screen-filling scrollview that has a small image in an imageview scaled to fit the whole scrollview and be scrollable? eg. A 720x1280 display has

Solution 1:

This works for me:

<ScrollViewxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ImageViewandroid:layout_width="720dp"android:layout_height="2160dp"android:src="@drawable/image"android:scaleType="fitXY"/></LinearLayout></ScrollView>

If you need to make this work for any screen size do it programmatically:

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imageView = (ImageView) findViewById(R.id.imageView);

    Displaydisplay= getWindowManager().getDefaultDisplay();
    Pointsize=newPoint();
    display.getSize(size);
    intwidth= size.x;
    intheight= size.y;

    imageView.getLayoutParams().width = width;
}

Solution 2:

if scroll view height and width is fill parent than if background is set with an small image it will automatically expand in your layout

Post a Comment for "How To Scale Small Imageview To Fill Large Scrollview?"