Android image not showing in imageview
Asked Answered
J

5

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>
Jenkins answered 9/4, 2017 at 20:46 Comment(0)
P
47

Use android:src instead of app:srcCompat

Pipes answered 9/4, 2017 at 20:48 Comment(4)
thanks this works! but why does app:srcCompat works in some situations?Jenkins
app:srcCompat is used for backwards compatibility with vector drawables for the support library. Perhaps in other instances you are using AppCompatImageView?Pipes
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 !!Mcclure
@Mcclure I would recommend starting a new question. I am no longer an Android developer :)Pipes
N
4

You cloud use Following code for set Image

android:src

or

android:background

Hope it help

Noahnoak answered 10/4, 2017 at 10:10 Comment(0)
B
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.

Bret answered 10/4, 2017 at 7:42 Comment(0)
S
1

application extend AppCompatImageView. I Use

android:foreground

this work for me.

Siloum answered 18/7, 2020 at 19:41 Comment(0)
L
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.

Lananna answered 13/10, 2021 at 7:56 Comment(1)
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.Candor

© 2022 - 2024 — McMap. All rights reserved.