ImageView的图像看起来像素化和低质量 [英] ImageView images seem pixelated and low quality

查看:234
本文介绍了ImageView的图像看起来像素化和低质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ImageView的图像像素化所有,低质量的,几乎是模糊的。他们都是在我的文件夹绘制48像素点¯x48像素 PNG文件。这是我的XML文件。

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s的android:layout_width =match_parent
    机器人:layout_height =match_parent机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    机器人:paddingBottom会=@扪/ activity_vertical_margin工具:上下文=。MainActivity
    机器人:ID =@ + ID /主
    机器人:背景=#ecf0f1>    < ImageView的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / ImageView的
        机器人:SRC =@绘制/ my_photo1
        安卓的onClick =VAL1
        机器人:layout_alignParentBottom =真
        机器人:layout_toLeftOf =@ + ID / ImageView的
        机器人:layout_toStartOf =@ + ID / ImageView的/>    <的TextView
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:textAppearance =机器人:ATTR / textAppearanceLarge
        机器人:文字=0
        机器人:ID =@ + ID / VAL
        机器人:textIsSelectable =假
        机器人:layout_alignParentTop =真
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentStart =真
        机器人:TEXTSIZE =60dp
        机器人:文字颜色=#ff34495e/>    < ImageView的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / ImageView的
        机器人:SRC =@绘制/ my_photo2
        机器人:知名度=隐形
        安卓的onClick =val2的
        机器人:layout_alignTop =@ + ID / ImageView的
        机器人:layout_toLeftOf =@ + ID / imageView2
        机器人:layout_toStartOf =@ + ID / imageView2/>    < ImageView的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / imageView2
        机器人:SRC =@绘制/ my_photo3
        机器人:知名度=隐形
        安卓的onClick =VAL3
        机器人:layout_alignTop =@ + ID / ImageView的
        机器人:layout_centerHorizo​​ntal =真/>    < ImageView的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / imageView3
        机器人:SRC =@绘制/ my_photo4
        机器人:知名度=隐形
        安卓的onClick =VAL4
        机器人:layout_alignTop =@ + ID / imageView2
        机器人:layout_toLeftOf =@ + ID / imageView4
        机器人:layout_toStartOf =@ + ID / imageView4/>    < ImageView的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / imageView4
        机器人:SRC =@绘制/ my_photo5
        机器人:知名度=隐形
        安卓的onClick =val5
        机器人:layout_alignTop =@ + ID / imageView3
        机器人:layout_toLeftOf =@ + ID / imageView5
        机器人:layout_toStartOf =@ + ID / imageView5/>    < ImageView的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / imageView5
        机器人:SRC =@绘制/ my_photo6
        机器人:知名度=隐形
        安卓的onClick =VAL6
        机器人:layout_alignTop =@ + ID / imageView4
        机器人:layout_alignParentRight =真
        机器人:layout_alignParentEnd =真/>    <的TextView
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:textAppearance =机器人:ATTR / textAppearanceSmall
        机器人:文字=纸杯蛋糕
        机器人:ID =@ + ID / TextView的
        机器人:layout_alignParentBottom =真
        机器人:layout_toLeftOf =@ + ID / ImageView的
        机器人:layout_toStartOf =@ + ID / ImageView的
        机器人:文字颜色=#ff34495e/>< / RelativeLayout的>


解决方案

有不同的图像大小不同的目录。请记住,PNG图片不一样SVG它们使用向量来调整大小不同,PNG是相当固定的大小,所以当Android使用你的应用程序在一个更大的屏幕尺寸还是小尺寸,例如它使用自动软件来调整即是图像为什么看起来模糊。

打开的src / main / RES DIR EN那里你会看到文件夹,如:结果

该目录/文件夹用于不同的分辨率,所以如果你需要使用图标example.png只是用不同的mipmap文件夹不同的分辨率。请检查上支持不同的屏幕尺寸的官方Android指南。

My Images in ImageView are all pixelated and low quality, almost blurry. They are all 48px x 48px PNG files in my drawable folder. Here's my XML file.

<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" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:id="@+id/main"
    android:background="#ecf0f1">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/my_photo1"
        android:onClick="val1"
        android:layout_alignParentBottom="true"
        android:layout_toLeftOf="@+id/ImageView"
        android:layout_toStartOf="@+id/ImageView" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="0"
        android:id="@+id/val"
        android:textIsSelectable="false"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textSize="60dp"
        android:textColor="#ff34495e" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ImageView"
        android:src="@drawable/my_photo2"
        android:visibility="invisible"
        android:onClick="val2"
        android:layout_alignTop="@+id/imageView"
        android:layout_toLeftOf="@+id/imageView2"
        android:layout_toStartOf="@+id/imageView2" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:src="@drawable/my_photo3"
        android:visibility="invisible"
        android:onClick="val3"
        android:layout_alignTop="@+id/ImageView"
        android:layout_centerHorizontal="true" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView3"
        android:src="@drawable/my_photo4"
        android:visibility="invisible"
        android:onClick="val4"
        android:layout_alignTop="@+id/imageView2"
        android:layout_toLeftOf="@+id/imageView4"
        android:layout_toStartOf="@+id/imageView4" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView4"
        android:src="@drawable/my_photo5"
        android:visibility="invisible"
        android:onClick="val5"
        android:layout_alignTop="@+id/imageView3"
        android:layout_toLeftOf="@+id/imageView5"
        android:layout_toStartOf="@+id/imageView5" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView5"
        android:src="@drawable/my_photo6"
        android:visibility="invisible"
        android:onClick="val6"
        android:layout_alignTop="@+id/imageView4"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Cup Cakes"
        android:id="@+id/textView"
        android:layout_alignParentBottom="true"
        android:layout_toLeftOf="@+id/imageView"
        android:layout_toStartOf="@+id/imageView"
        android:textColor="#ff34495e" />

</RelativeLayout>

解决方案

There are different directories for different image sizes. Remember that png images aren't as as SVG which use vectors to resize to different size, png are rather fixed size so when android uses your app in a bigger screen size or a small size such it uses automatic software to resize the image that is why it seems fuzzy.

Open your src/main/resdir en there you shall see folders such as:

This directories/folders are used for different resolutions so if you need to use icon-example.png just use the different mipmap folders for different resolutions. Please check the official android guide on supporting different screen sizes.

这篇关于ImageView的图像看起来像素化和低质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆