简体   繁体   English

Android 图像未显示在 imageview 中

[英]Android image not showing in imageview

I am having problems with my xml file.我的 xml 文件有问题。 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.我正在使用的照片也在 android studio 中显示,但不在我的手机上。 You can find my xml below.您可以在下面找到我的 xml。

<?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>

使用android:src而不是app:srcCompat

You cloud use Following code for set Image您云使用以下代码设置图像

android:src

or或者

android:background

Hope it help希望有帮助

I think You should edit srcCompat to src.我认为您应该将 srcCompat 编辑为 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. src 用于源代码,而 sourceCompat 用于向后兼容在 ICS 上运行的 Android 设备的矢量可绘制文件 - IceCream Sandwich。

application extend AppCompatImageView.应用程序扩展 AppCompatImageView。 I Use我用

android:foreground

this work for me.这对我有用。

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.将图像调整为较小的尺寸(在 Windows 中使用油漆)并使用它,这可能会奏效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM