Android 底部工作表在运行时不显示imageView,但在预览中显示
我为我的底部工作表制作了xml文件,一切都很好。它显示文本,但不显示图像。虽然在预览中我有ImageView,但当我运行应用程序时,图像消失了 下面是我的下表xml代码的一部分: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 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" />