Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constraint layout not showing image from ImageView when app run

I am trying to add some Images by ImageView in Android Activity(ConstraintLayout), on Android Studio Preview screen, it's showing images correctly, but when I am running the app on real device or emulator, it's not showing the image.

Below is the code which I am using,

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.vchamps.android.staffast.ProfessionalsCalc"
    android:background="@color/colorPrimary">

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guidelineVertical1"
        app:layout_constraintGuide_percent="0.1"
        android:orientation="vertical"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="39dp" />

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guidelineVertical2"
        app:layout_constraintGuide_percent="0.25"
        android:orientation="vertical"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="96dp" />

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guidelineHorizontal"
        app:layout_constraintGuide_begin="87dp"
        android:orientation="horizontal"
        tools:layout_editor_absoluteY="87dp"
        tools:layout_editor_absoluteX="0dp" />

    <ImageView
        android:visibility="visible"
        android:id="@+id/imgRate"
        android:layout_width="@dimen/rates_icon_size"
        android:layout_height="@dimen/rates_icon_size"
        app:srcCompat="@drawable/icon_rates"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true"
        app:layout_constraintTop_toTopOf="@+id/guidelineHorizontal"
        android:layout_marginTop="27dp"
        android:layout_marginLeft="0dp"
        app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical1"
        />
    <ImageView
        android:visibility="visible"
        android:id="@+id/imgSchedule"
        android:layout_width="@dimen/rates_icon_size"
        android:layout_height="@dimen/rates_icon_size"
        app:srcCompat="@drawable/icon_schedule"
        android:layout_marginTop="10dp"
        app:layout_constraintTop_toBottomOf="@+id/imgRate"
        app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical1"
        android:scaleType="fitCenter"
         />

    <ImageView
        android:visibility="visible"
        android:id="@+id/imgPayout"
        android:layout_width="36dp"
        android:layout_height="36dp"
        app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical1"
        app:srcCompat="@drawable/icon_payout"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/imgSchedule"
        android:scaleType="fitCenter"
        />

    <TextView
        android:id="@+id/tvRate"
        style="@style/fontRateScreenTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="33dp"
        android:text="Industry Leading Rates"
        app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical2"
        app:layout_constraintTop_toTopOf="@+id/guidelineHorizontal" />

    <TextView
        android:id="@+id/tvSchedule"
        style="@style/fontRateScreenTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="44dp"
        android:text="Flexible Schedule"
        app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical2"
        app:layout_constraintTop_toTopOf="@+id/tvRate" />

    <TextView
        android:id="@+id/tvPayout"
        style="@style/fontRateScreenTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="48dp"
        android:text="Quick and Easy Payout"
        app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical2"
        app:layout_constraintTop_toTopOf="@+id/tvSchedule" />

    <Button
        android:id="@+id/btnWork"
        style="@style/ButtonStyle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:text="CLICK ME"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />


</android.support.constraint.ConstraintLayout>

The UI Preview in Android Studio is as below,

UI Preview

We can see that 3 Images are getting displayed here,

But when I run the application on emulator or on real device, it's not showing any of 3 images. Below is the screenshot of the emulator,

Emulator View

  • Value of @dimen/rates_icon_size: 36dp
  • Three Images Dimensions,
    1. icon_rates : 87x59 Pixels
    2. icon_schedule : 88x78 Pixels
    3. icon_payout : 60x82 Pixels

Please help me by providing resolution of the query, Thanks in advance.

like image 725
vChamps Avatar asked May 01 '17 06:05

vChamps


2 Answers

In ImageView instead of using srcCompact use src

   <ImageView
    android:visibility="visible"
    android:id="@+id/imgRate"
    android:layout_width="@dimen/rates_icon_size"
    android:layout_height="@dimen/rates_icon_size"
    app:src="@drawable/icon_rates"
    android:scaleType="fitCenter"
    android:adjustViewBounds="true"
    app:layout_constraintTop_toTopOf="@+id/guidelineHorizontal"
    android:layout_marginTop="27dp"
    android:layout_marginLeft="0dp"
    app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical1"
    />

instead of

    <ImageView
    android:visibility="visible"
    android:id="@+id/imgRate"
    android:layout_width="@dimen/rates_icon_size"
    android:layout_height="@dimen/rates_icon_size"
    app:srcCompat="@drawable/icon_rates"
    android:scaleType="fitCenter"
    android:adjustViewBounds="true"
    app:layout_constraintTop_toTopOf="@+id/guidelineHorizontal"
    android:layout_marginTop="27dp"
    android:layout_marginLeft="0dp"
    app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical1"
    />
like image 167
Anmol317 Avatar answered Oct 15 '22 15:10

Anmol317


use android:src="@drawable/icon_rates" sometime app:srcCompat="@drawable/icon_rates" not work.

<ImageView
    android:visibility="visible"
    android:id="@+id/imgRate"
    android:layout_width="@dimen/rates_icon_size"
    android:layout_height="@dimen/rates_icon_size"
    android:src="@drawable/icon_rates"
    android:scaleType="fitCenter"
    android:adjustViewBounds="true"
    app:layout_constraintTop_toTopOf="@+id/guidelineHorizontal"
    android:layout_marginTop="27dp"
    android:layout_marginLeft="0dp"
    app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical1"
/>
like image 29
Dev. Jaykrushna Avatar answered Oct 15 '22 15:10

Dev. Jaykrushna