2
votes

I've read all there is to read in terms of supporting different screen desnities. And, I have supplied proper variations of the images being display to appropriate folders. However, I am bewildered by something. The documentation for ImageView says that setting android:layout_width and android:layout_height to "fill_parent"/"match_parent" will result in the image stretching to fill the screen. (This seems necessary since not all screen densities offer the same size/pixel count screens and I don't want those extra few pixels to result in padding on the bottom of the screen) This seems to work any other time, but is not working for me when the ImageView is placed inside of a Horizontalscrollview and the width of the image is longer than that of the screen.

My code below: (The activity is set to landscape in my manifest)

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/hscrollview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    android:fadingEdge="none"
    android:scrollbars="none"
    android:overScrollMode="never" >

<RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    android:fadingEdge="none"
    android:scrollbars="none"
    android:overScrollMode="never" >

<ImageView
    android:id="@+id/MapImageView"
    android:src="@drawable/map"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent" />
</RelativeLayout>
</HorizontalScrollView>

Edit: I replaced :src with :background to no effect.

This is the effect I get on devices like tablets. Ideally I want the image to fill the entire screen, like it does, below, on a phone with typical 480x800 resolution or the like.

This is the effect I get on devices like tablets.  Ideally I want the image to fill the entire screen, like it does when on a phone with typical 480x800 resolution or the like.

2
Please post the picture of what you get with the above data and what originally you want.And use "background" instead of "src" in ImageViewManishika
Edits have been added. Changing :src to :background had no effect.Joseph.M
Would it be best to set the size in terms of "dp" for height, instead?Joseph.M
Don't use hard coded values for height or width .This is a not good practiceManishika

2 Answers

7
votes

Try using android:scaleType="fitXY" in your ImageView.

0
votes

This is working for me:

<ImageView
    android:id="@+id/main_imageView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="42dp"
    android:alpha="0.5"
    android:src="@drawable/img_alchemy2" />

It is a portrait image that fills the screen in portrait mode, and in landscape it fills it vertically without stretching it horizontally.