简体   繁体   中英

How to avoid image stretching in imageview

I have a image with 320x480 and i am running the application in device with 320x480. I set Image as android:background then my image is stretched. but if i use android:src then i am getting white space behind the image as if the image didnot cover the screen. How to set image in image view so that my image will neither be stretched and it will cover the whole screen.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    >
    <ImageView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/about1"/>
</LinearLayout>

Take a look at the ImageView property adjustViewBounds .

Setting that to true has helped me in similar situations

Why don't you set the image as the background of the LinearLayout? If you do want to use the ImageView you should specify 'fill_parent' for the layout_height and layout_width.

You have to give height and width of image like you have image of 320*480 you have mention this size in xml while declaring the image and store the image in (drawable-mdpi)folder and then run it.

@Deepakkk

i think you have stored image in drawable in hdpi or ldpi which are for high desity or low density

for emulator of size 320 * 480 you should store your source image in mdpi在此处输入图像描述

change height of image to fill parent

try this

 <manifest xmlns:android="http://schemas.android.com/apk/res/android">
        <supports-screens
            android:smallScreens="true"
            android:normalScreens="true"
            android:largeScreens="true"
            android:xlargeScreens="true"
            android:anyDensity="true" />
        ...
    </manifest>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM