ImageView images seem pixelated and low quality

浪尽此生 提交于 2020-01-15 11:00:09

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/31506472/imageview-images-seem-pixelated-and-low-quality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!