簡體   English   中英

ImageView 顯示白色圖像 Android Studio Kotlin

[英]ImageView Showing White Image Android Studio Kotlin

我正在嘗試在我的應用程序中顯示圖像,但沒有顯示。 僅顯示一個白色方塊來代替圖像。 這是我的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" />

完整的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>

@drawable/calc

在此處輸入圖片說明

任何幫助,將不勝感激。 謝謝!

PS:我在Stack Overflow上提到了類似的問題,但他們沒有解決我的問題。 如果我的問題已經被問到,抱歉。 謝謝!

嘗試交換這條線

android:background="@drawable/calc"

android:src="@drawable/calc"

您能先嘗試刪除這些填充嗎? 喜歡

<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" />

您的邊距相當大,或者您可以粘貼您在 LayoutInspector 中看到的內容(最好使用 imageView 的參數)

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

也許您的圖像在 drawable-v21 文件夾中。

使用Windows 資源管理器檢查您的圖像目錄

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM