How can I put a background image in an ImageView without it being blurred?

3

What I want is to put a background image in a ImageView , but when I run the app this image looks blurry and I do not know why, I also put a Play icon and the same thing happens go fuzzy Does this have something to do with the image or is there a way to improve the quality in which the image is displayed?

Java Code:

Movie Class:

private String nombre;
private String sinopsis;
private String genero;
private int duracion;
private int fondo;
private int fondoSecundario;

public Pelicula(String Nombre,String Sinopsis,String Genero,int Duracion,int Fondo,int FondoSecundario)
{
    nombre = Nombre;
    sinopsis = Sinopsis;
    genero = Genero;
    duracion = Duracion;
    fondo = Fondo;
    fondoSecundario = FondoSecundario;
}

protected Pelicula(Parcel in)
{
    nombre = in.readString();
    sinopsis = in.readString();
    genero = in.readString();
    duracion = in.readInt();
    fondo = in.readInt();
    fondoSecundario = in.readInt();
}

 public static final Creator<Pelicula> CREATOR = new Creator<Pelicula>()
{
    @Override
    public Pelicula createFromParcel(Parcel in)
    {
        return new Pelicula(in);
    }

    @Override
    public Pelicula[] newArray(int size)
    {
        return new Pelicula[size];
    }
};

public String Nombre(){return nombre;}
public String Sinopsis(){return sinopsis;}
public String Genero(){return genero;}
public int Duracion(){return duracion;}
public int Fondo(){return fondo;}
public int FondoSecundario(){return fondoSecundario;}

@Override
public int describeContents()
{
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags)
{
    dest.writeString(nombre);
    dest.writeString(sinopsis);
    dest.writeString(genero);
    dest.writeInt(duracion);
    dest.writeInt(fondo);
    dest.writeInt(fondoSecundario);
}

So I add an object of the type Film:

listaSerie.add(new Serie("The Strain","Sinopsis","Thriller",1,R.drawable.the_strain_fondo,R.drawable.the_strain_fondo1));

EntroPelicula Class:

Bundle bundle = getIntent().getExtras();
    pelicula = bundle.getParcelable("Pelicula");

    btnReproducirPelicula = (ImageView)findViewById(R.id.btnReproducir);
    mostrarGeneroPelicula = (TextView)findViewById(R.id.mostrarGeneroPelicula);
    mostrarSinopsisPelicula = (TextView)findViewById(R.id.mostrarSinopsisPelicula);


    mostrarGeneroPelicula.setText("Genero: " + pelicula.Genero());
    mostrarSinopsisPelicula.setText("Sinopsis:" + "\n" + "\n" + pelicula.Sinopsis());
    btnReproducirPelicula.setBackgroundResource(fondoSecundario);

    btnReproducirPelicula.setOnClickListener(this);

movie is an object of type Film .

Secondary Background () returns the id of the image that is in the Drawable.

XML Code:

 <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:background="#212121"
tools:context="com.example.erick.depelis.EntroPelicula">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/btnReproducir"
            android:layout_width="match_parent"
            android:layout_height="190dp"
        />

        <TextView
            android:id="@+id/mostrarGeneroPelicula"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#FFF"
            android:textSize="20dp"
        />

        <TextView
            android:id="@+id/mostrarSinopsisPelicula"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:textSize="15dp"
            android:textColor="#FFF"
        />
    </LinearLayout>
</ScrollView>

</LinearLayout>
    
asked by Erick Raul Marquez 28.07.2016 в 22:40
source

2 answers

1

Reviewing your ImageView , the problem seems to be the measurement of the image, for example if I load an image of size 200x200 pixels in the ImageView it will show correctly:

But instead if I load a very small image, for example 10x10 pixels in the ImageView would be blurred because the resolution is lost when it expands.

To solve this, simply ensure that the image is of a suitable size so that it can be displayed in the 190dp container.

    
answered by 29.07.2016 / 01:41
source
1

Android has an extensive variety of devices, that creates conflict with the resolutions of the images, to avoid these problems you have to create different folders, eg:

Android is responsible for interpreting those files, when it comes to assigning the image to the view it will not give you any inconveniences, it will remain "setBackgroundResource (R.drawable.lucy_fondo1);"

In the drawable-hdpi folder goes the original image that would be 100% size in the following folders you have to add the same image but of different sizes I leave the data:

-drawable-hdpi    -> 100% res: 426dp x 320dp
-drawable-mdpi    -> 150% res: 470dp x 320dp
-drawable-xhdpi   -> 200% res: 640dp x 480dp
-drawable-xxhdpi  -> 300% res: 960dp x 720dp
-drawable-xxxhdpi -> 400% res: resoluciones mayor a 960dp x 720dp

here I leave the official documentation of Android: link

Greetings!

    
answered by 29.07.2016 в 15:05