简体   繁体   English

如何避免 imageview 中的图像拉伸

[英]How to avoid image stretching in imageview

I have a image with 320x480 and i am running the application in device with 320x480.我有一个 320x480 的图像,我在 320x480 的设备中运行应用程序。 I set Image as android:background then my image is stretched.我将图像设置为android:background然后我的图像被拉伸。 but if i use android:src then i am getting white space behind the image as if the image didnot cover the screen.但是如果我使用android:src那么我会在图像后面出现空白,就好像图像没有覆盖屏幕一样。 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 .看看 ImageView 属性adjustViewBounds

Setting that to true has helped me in similar situations将其设置为 true 在类似情况下对我有所帮助

Why don't you set the image as the background of the LinearLayout?为什么不将图像设置为 LinearLayout 的背景? If you do want to use the ImageView you should specify 'fill_parent' for the layout_height and layout_width.如果您确实想使用 ImageView,您应该为 layout_height 和 layout_width 指定“fill_parent”。

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.你必须给出图像的高度和宽度,就像你有 320*480 的图像一样,你在 xml 中提到了这个尺寸,同时声明图像并将图像存储在 (drawable-mdpi) 文件夹中,然后运行它。

@Deepakkk @Deepakkk

i think you have stored image in drawable in hdpi or ldpi which are for high desity or low density我认为您已将图像存储在 hdpi 或 ldpi 中,用于高密度或低密度

for emulator of size 320 * 480 you should store your source image in mdpi对于大小为 320 * 480 的模拟器,您应该将源图像存储在 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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