具有相同分辨率的图像不适合布局imageview

时间:2021-12-17 21:13:56

Problem: trying to give multi device support screen for a simple layout but in Nexus 6 its creating the problem,means not showing fit. It's side is cutting down where as per as docs for nexus-6 resolution is 1440*2560 and image should be in drawable-xxxhdpi .so i keep a image with resolution of 1440*2560.

问题:尝试为简单的布局提供多设备支持屏幕,但在Nexus 6中创建问题,意味着不显示合适。它的一面是削减,因为nexus-6分辨率的文档是1440 * 2560,图像应该是drawable-xxxhdpi。所以我保留了分辨率为1440 * 2560的图像。

<RelativeLayout xmlns: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">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon"
        android:id="@+id/imv" />
</RelativeLayout>

if i ll give match_parent so obvious it will stretch the image. Please help me to get out of it. Here is screen shots of screen -

如果我给match_parent如此明显它将拉伸图像。请帮我摆脱它。这是屏幕截图 -

http://s10.postimg.org/43od5j5h5/screen_shot_layout.png

3 个解决方案

#1


0  

Set the width of the Image to fill_parent (you can set margins if you want a bit smaller imageView or you could also just set a fixed width)

将图像的宽度设置为fill_parent(如果您想要更小的imageView,您可以设置边距,或者您也可以设置固定的宽度)

Use android:adjustViewBounds to keep aspect ratio

使用android:adjustViewBounds来保持宽高比

Set height to wrap_content (it will take whatever it takes to maintain aspect ratio)

将height设置为wrap_content(它将采取保持宽高比所需的一切)

<ImageView
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:adjustViewBounds="true"
       android:src="@drawable/icon"
       android:id="@+id/imv"
       android:scaleType="fitCenter" />

#2


0  

If you want to fit the image on the imageview, replace android:src with android:background in the ImageView in the xml code.

如果要将图像放在imageview上,请在xml代码的ImageView中将android:src替换为android:background。

#3


0  

Try to use these lines of code in the layout

尝试在布局中使用这些代码行

 <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/icon"
    android:scaleType="fitXY"
    android:id="@+id/imv" />

#1


0  

Set the width of the Image to fill_parent (you can set margins if you want a bit smaller imageView or you could also just set a fixed width)

将图像的宽度设置为fill_parent(如果您想要更小的imageView,您可以设置边距,或者您也可以设置固定的宽度)

Use android:adjustViewBounds to keep aspect ratio

使用android:adjustViewBounds来保持宽高比

Set height to wrap_content (it will take whatever it takes to maintain aspect ratio)

将height设置为wrap_content(它将采取保持宽高比所需的一切)

<ImageView
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:adjustViewBounds="true"
       android:src="@drawable/icon"
       android:id="@+id/imv"
       android:scaleType="fitCenter" />

#2


0  

If you want to fit the image on the imageview, replace android:src with android:background in the ImageView in the xml code.

如果要将图像放在imageview上,请在xml代码的ImageView中将android:src替换为android:background。

#3


0  

Try to use these lines of code in the layout

尝试在布局中使用这些代码行

 <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/icon"
    android:scaleType="fitXY"
    android:id="@+id/imv" />