【问题标题】:Image with same resolution not fit on layout imageview具有相同分辨率的图像不适合布局图像视图
【发布时间】:2015-12-02 21:49:17
【问题描述】:

问题:试图为简单的布局提供多设备支持屏幕,但在 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>

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

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

【问题讨论】:

  • 使用android:scaleType="fitXY" 来匹配ImageView 中的图像
  • @ChiragSavsani 我知道,但如果与分辨率不匹配,它会拉伸图像
  • 然后尽可能使用9patch drawable。
  • @ChiragSavsani 图像不是一种可以制作 9patch 的图像。还有其他方法可以使用吗?比如不同的文件夹或不同的图像大小?
  • 你试过用 (fiil_parent) 代替 wrap_content 吗?

标签: android android-layout android-activity


【解决方案1】:

将 Image 的宽度设置为 fill_parent(如果你想要更小的 imageView 可以设置边距,或者你也可以设置一个固定的宽度)

使用 android:adjustViewBounds 保持纵横比

将高度设置为 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】:

    如果要让图片适合imageview,请在xml代码中的ImageView中将android:src替换为android:background。

    【讨论】:

    【解决方案3】:

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

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

    【讨论】:

    • 但是如果分辨率不符合我上面已经提到的,它会拉伸图像,有没有其他方法来匹配标准?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 2018-07-13
    相关资源
    最近更新 更多