【问题标题】:png images getting streached inside imageviewpng 图像在 imageview 中被拉伸
【发布时间】:2016-09-15 19:12:46
【问题描述】:
    <LinearLayout 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"
    android:orientation="vertical"
    android:padding="@dimen/contactUsPad"
    tools:context="com.onqanetapp.mp.onqanet.ContactUs_Fragment">

    <!-- TODO: Update blank fragment layout -->
    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".2"
        android:text="@string/contactUsAddHead"
        android:textSize="20sp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="@string/contactUsAdd"
        android:textSize="18sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".6"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/ivFb"
            android:layout_width="@dimen/socialImageWidth"
            android:layout_height="@dimen/socialImageHeight"
            android:layout_marginRight="@dimen/socialImageRightMargin"
            android:src="@drawable/f" />

        <ImageView
            android:id="@+id/ivIn"
            android:layout_width="@dimen/socialImageWidth"
            android:layout_height="@dimen/socialImageHeight"
            android:layout_marginRight="@dimen/socialImageRightMargin"
            android:src="@drawable/in" />

        <ImageView
            android:id="@+id/ivTw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="@dimen/socialImageRightMargin"
            android:src="@drawable/tw" />
    </LinearLayout>


</LinearLayout>

尺寸

<dimen name="socialImageHeight">50dp</dimen>
<dimen name="socialImageWidth">50dp</dimen>
<dimen name="socialImageRightMargin">10dp</dimen>

图片

this is final layout screenshot and i did't change the last imageview to show you guys the problem

信息

  1. 所有图片均为 png
  2. 第一个可绘制的开始是 48x48

问题

  1. wrap_content 应该为这些图像提供分辨率,即 48x48 ,但事实并非如此。
  2. 当我给它们 50dp 的宽度和高度时,它们看起来被拉伸了,但是 看起来也越界了。
  3. 72x72 分辨率也很累,但还是一样

【问题讨论】:

  • 将此属性用于ImageView android:scaleType="fitXY"
  • 你没有按照排版规则,请先修复。
  • @AshishShukla ...你能指定什么...我是Android新手。
  • @Mrin 您没有正确使用 android:layout_weight 属性。

标签: android imageview


【解决方案1】:

您必须根据屏幕大小调整图像边界。

android:scaleType="centerInside"

它不会拉伸或裁剪图像。它只会调整图像的大小

【讨论】:

    【解决方案2】:

    尝试在 imageView xml 中添加以下行:

            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
    

        android:adjustViewBounds="true"
        android:scaleType="fitXY"; //fitCenter, or change according to your requirement
    

    对于缩放图像视图的边界: https://developer.android.com/reference/android/widget/ImageView.ScaleType.html

    【讨论】:

      【解决方案3】:

      谢谢大家的回答。

      但对我来说没有任何效果。无论我做什么,图像都不会清晰或清晰,所以我使用 SVG。

      ===========

      http://www.flaticon.com/下载的svg图标

      然后使用 Vector Asset Studio(https://developer.android.com/studio/write/vector-asset-studio.html)

      (右键单击 res 文件夹并选择 New > Vector Asset。) 将 SVG 导入矢量资产工作室,然后将 svg 转换为可绘制的 xml。 现在它的工作就像一个魅力。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多