7

I am having problems with my xml file. I want to show a picture but the picture is not showing. Strange thing is I am using the same picture in an other part of my app and there everithing is working fine. The foto I am using is also showing in android studio but not on my phone. You can find my xml below.

<?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"
android:background="@color/backgroundcollor">  

 <ImageView
    android:id="@+id/imgPersoon"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="65dp"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    app:srcCompat="@drawable/persoon" />

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imgPersoon"
    android:fillViewport="false"
    android:orientation="vertical"
    android:padding="10dp">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <TextView
            android:id="@+id/txtName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_marginTop="14dp"
            android:text="Naam:"
            android:textAlignment="center"
            android:textColor="@color/colorPrimary" />

    <EditText
            android:id="@+id/txtFirstName"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:layout_below="@+id/txtName"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/rounded_button_grey"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="Name"
            android:textSize="14sp" />

    <EditText
        android:id="@+id/txtLastName"
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:layout_below="@+id/txtFirstName"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/rounded_button_grey"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Name"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/txtDate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtLastName"
        android:layout_marginTop="14dp"
        android:text="Naam:"
        android:textAlignment="center"
        android:textColor="@color/colorPrimary" />

</RelativeLayout>

</ScrollView>
</RelativeLayout>
Mickey Evers
  • 151
  • 2
  • 4
  • 12

5 Answers5

46

Use android:src instead of app:srcCompat

Josh Laird
  • 6,974
  • 7
  • 38
  • 69
  • 3
    thanks this works! but why does app:srcCompat works in some situations? – Mickey Evers Apr 09 '17 at 20:50
  • 3
    `app:srcCompat` is used for backwards compatibility with vector drawables for the support library. Perhaps in other instances you are using `AppCompatImageView`? – Josh Laird Apr 09 '17 at 20:53
  • 1
    But , im using srccompat at many places, and it didn;t fail ! and it fails only at some situation ! why so? is it file specific? And the IDE shows warning to change to srcCompat !! – adi Jan 02 '20 at 03:07
  • @adi I would recommend starting a new question. I am no longer an Android developer :) – Josh Laird Jan 02 '20 at 10:52
4

You cloud use Following code for set Image

android:src

or

android:background

Hope it help

1

I think You should edit srcCompat to src. src is meant for source and sourceCompat Is for Backwards Compatiblity Of Vector Drawable Files For Android Devices Running On and below ICS -- IceCream Sandwich.

Anuj Kumar
  • 1,092
  • 1
  • 12
  • 26
1

application extend AppCompatImageView. I Use

android:foreground

this work for me.

Sunil Shakya
  • 8,097
  • 2
  • 17
  • 20
1

The bigger size of an image could be an issue as well. Resize the image to a smaller size (using paint in windows) and use it, this might work.

Manas
  • 888
  • 10
  • 20
  • Thanks, it worked. I had a large resolution image that was not shown on circular image view. Following your solution, I reduced the image resolution and now it is working. – Rahat Shah Sep 14 '22 at 16:13