0

I created an Activity, which I load from a fragment within my "main" activity. Within this new activity I placed an ImageView with an image from my drawable directory (I have about 10 other drawables I present the exact same way in the main activity).

The problem is that although in the IDE I see the image, it is not displayed in run time (via the simulator). -- to clarify, the image is static hence the difference compared to other questions (I'm not loading it by code).

Any ideas on how to solve it? My hunch is that it relates to the fact it's a new activity, but I'm new to android development, so I can't base it on any knowledge...

I did not add any code to the java section of the activity (didn't touch any "on.." nor added functionality to this specific file)

P.S. I tried cleaning the project, tried presenting an image that is presented on the main activity, and restarting anything that I can... nothing helped :(

My Activity xml is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="reducted">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <ImageView
            android:id="@+id/manageSubscriptionScreenLogo"
            android:layout_width="match_parent"
            android:layout_height="110dp"
            app:srcCompat="@drawable/managesubscription_header" />
    </LinearLayout>
</RelativeLayout>
  • It doesn't matter I take the ImageView and place it outside of the LinearLayout (and remove it), or change the size to wrap_content or match_parent (I tried all combinations), the image is not presented.

How it looks in the IDE: enter image description here

And how it looks in run time:

enter image description here

evenro
  • 2,626
  • 20
  • 35
  • What do you mean by "there is no code in the java part"? Do you not have a `setContentView` call in your activity? – ephemient Mar 15 '17 at 04:06
  • I clarified the text ... I meant that I did not edit the java files created by the IDE, therefor there is not "my code", all I do is simply trying to place a static image in the activity.. (I plan to add a lot of things there, but this issue just halted me..) – evenro Mar 15 '17 at 04:09
  • 1
    try android:src="@drawable/managesubscription_header" in your xml. – Sangram Haladkar Mar 15 '17 at 04:12

1 Answers1

3

Try using android:src="@drawable/managesubscrip_header" instead of app:srcCompat="@drawable/managesubscription_header" in ImageView to avoid automatic scaling of the drawable.

Let me know if it helps

Suhayl SH
  • 1,213
  • 1
  • 11
  • 16
  • 1
    what is "automatic scaling" here? it seems to me it does scale the image... (it now works as I expect, but I want to understand why it didn't work before and with "src" instead it does...) – evenro Mar 15 '17 at 04:17
  • When we use a single vector drawable instead of multiple PNG files, using this tag the vector drawable (image generally in XML format) scales automatically as per screen size /screen density without loosing any pixels. For more detailed description follow this link http://stackoverflow.com/questions/40624554/android-what-is-the-difference-between-appsrccompat-and-androidsrc – Suhayl SH Mar 15 '17 at 04:22
  • Please mark the answer correct if it helped .. Thanks – Suhayl SH Mar 15 '17 at 04:22
  • The only thing I don't understand is why it works, even with the same image, on other activities with srcCompat and not with this activity.. or in other words - what's special with this activity? – evenro Mar 15 '17 at 04:25
  • Try changing the ImageView height to wrap_content and check. – Suhayl SH Mar 15 '17 at 04:27
  • If it's possible for you, try posting the entire code. I ll try to reproduce this scenario. – Suhayl SH Mar 15 '17 at 04:30
  • As of Android Support Library 23.3.0, support vector drawables can only be loaded via app:srcCompat .you need to add vectorDrawables.useSupportLibrary = true to your build.gradle file – Sangram Haladkar Mar 15 '17 at 04:35