简体   繁体   English

ImageView 显示白色图像 Android Studio Kotlin

[英]ImageView Showing White Image Android Studio Kotlin

I am trying to display an image in my app, but it isn't getting displayed.我正在尝试在我的应用程序中显示图像,但没有显示。 Only a white square is displayed in place of the image.仅显示一个白色方块来代替图像。 Here is the ImageView part of my xml :这是我的xmlImageView部分:

<ImageView
        android:id="@+id/calcImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="28dp"
        android:layout_marginTop="222dp"
        android:layout_marginEnd="41dp"
        android:contentDescription="@null"
        android:layout_marginBottom="364dp"
        android:background="@drawable/calc"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/appName"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

Full xml :完整的xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">
    
    <TextView
        android:id="@+id/appName"
        android:gravity="center"
        android:layout_width="112dp"
        android:layout_height="73dp"
        android:text="Calc"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.886"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.414" />

    <ImageView
        android:id="@+id/calcImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/calc"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/appName"
        app:layout_constraintHorizontal_bias="0.51"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Image in @drawable/calc : @drawable/calc

在此处输入图片说明

Any help would be appreciated.任何帮助,将不胜感激。 Thanks!谢谢!

PS: I have referred to similar questions on Stack Overflow , but they didn't solve my problem. PS:我在Stack Overflow上提到了类似的问题,但他们没有解决我的问题。 If my question has already been asked, apologies.如果我的问题已经被问到,抱歉。 Thanks!谢谢!

try to exchange this line尝试交换这条线

android:background="@drawable/calc"

to

android:src="@drawable/calc"

Could you try to remove those padding first?您能先尝试删除这些填充吗? Like喜欢

<ImageView
        android:id="@+id/calcImg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/calc"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/appName"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

Your margin is quite large, or can you paste what you see in LayoutInspector (better with the imageView's parameters)您的边距相当大,或者您可以粘贴您在 LayoutInspector 中看到的内容(最好使用 imageView 的参数)

Use

android:src="@drawable/calc"
app:layout_constraintEnd_toStartOf="parent"

maybe your image is in drawable-v21 folder.也许您的图像在 drawable-v21 文件夹中。

check your image directory with windows explorer使用Windows 资源管理器检查您的图像目录

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

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