Home > Net >  My Imageview is showing my image in design but not in my mobile which I am using as avd emulator rep
My Imageview is showing my image in design but not in my mobile which I am using as avd emulator rep

Time:06-02

I was making an android whose XML code is this

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@ id/imageView2"
        android:layout_width="146dp"
        android:layout_height="0dp"
        android:layout_marginTop="66dp"
        android:layout_marginBottom="87dp"
        app:layout_constraintBottom_toTopOf="@ id/textView3"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:srcCompat="@drawable/download" />

    <TextView
        android:id="@ id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="411dp"
        android:text="Welcome to javascript quiz"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/imageView2" />

    <TextView
        android:id="@ id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        android:layout_marginEnd="29dp"
        android:text="Is Javascript was introduce in 1983?"
        android:textSize="20sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/textView3" />
</androidx.constraintlayout.widget.ConstraintLayout>

And Java code is this

package com.example.chapter4practise;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

I can see my image in design mode but when I am launching it on mobile which I am using AVD replacement then my image is not showing. My Image is less than 5kb and it is inside the drawable folder. In XML of ImageView, I have tried three types of src which and tools:srcCompat="@drawable/download" , tools:srcCompat="@drawable/download" and android:src="@drawable/download"

CodePudding user response:

tools:srcCompat="@drawable/download"

The above tag is used to show the image in the preview mode in your layout editor.

android:src="@drawable/download"

The above tag is used to set a drawable as the content of this ImageView.It will display in its original size. No automatic scaling.

  • Related