Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 底部工作表在运行时不显示imageView,但在预览中显示_Android_Xml_Android Studio_Android Layout - Fatal编程技术网

Android 底部工作表在运行时不显示imageView,但在预览中显示

Android 底部工作表在运行时不显示imageView,但在预览中显示,android,xml,android-studio,android-layout,Android,Xml,Android Studio,Android Layout,我为我的底部工作表制作了xml文件,一切都很好。它显示文本,但不显示图像。虽然在预览中我有ImageView,但当我运行应用程序时,图像消失了 下面是我的下表xml代码的一部分: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/andr

我为我的底部工作表制作了xml文件,一切都很好。它显示文本,但不显示图像。虽然在预览中我有ImageView,但当我运行应用程序时,图像消失了

下面是我的下表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:id="@+id/trip_details"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">


    <TextView
        android:id="@+id/carModel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="25dp"
        android:layout_marginTop="22dp"
        android:fontFamily="@font/roboto_medium"
        android:text="@string/white_cobalt_textView"
        android:textColor="#2C2C2C"
        android:textSize="18sp"
        android:textStyle="bold"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/licensePlate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginTop="55dp"
        android:fontFamily="@font/roboto_medium"
        android:lineSpacingMultiplier="1.20"
        android:text="01 | A 717 CB"
        android:textColor="#2C2C2C"
        android:textSize="20sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/callingBtn"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="18dp"
        android:contentDescription="@string/call_button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/bnt_call" />

</androidx.constraintlayout.widget.ConstraintLayout>

我在谷歌地图活动中使用底部表单,下面是附在底部表单上的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 
    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=".MapsActivity">

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <include layout="@layout/bottom_sheet_trip_details" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

我用
android:background=“@drawable/”
属性设置了图像,它成功了


但我不知道为什么它没有显示带有属性的图像:
app:srcCompat=“@drawable/”
app:src=“”

我使用
android:background=“@drawable/”
属性设置图像,它成功了


但我不知道为什么它没有显示带有属性的图像:
app:srcCompat=“@drawable/”
app:src=“

您需要使用
AppCompatImageView
来使用
srcCompat

试试这个:

<androidx.appcompat.widget.AppCompatImageView
    android:id="@+id/callingBtn"
    android:layout_width="90dp"
    android:layout_height="90dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="18dp"
    android:contentDescription="@string/call_button"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/bnt_call" />

您需要使用
AppCompatImageView
才能使用
srcCompat

试试这个:

<androidx.appcompat.widget.AppCompatImageView
    android:id="@+id/callingBtn"
    android:layout_width="90dp"
    android:layout_height="90dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="18dp"
    android:contentDescription="@string/call_button"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/bnt_call" />