我正在設定一個recylcerview,但當應用程式運行時,它沒有顯示任何影像,但它們確實顯示在設計視圖上,我嘗試了AppcompatImageView和ImageView,但都失敗了。只有文本視圖顯示。非常感謝您的幫助
<?xml version="1.0" encoding="utf-8"? >
<androidx.cardview.widget.CardView。
xmlns:android="http://schemas.android.com/apk/res/android"/span>
xmlns:tools="http://schemas.android.com/tools"。
xmlns:cardView="http://schemas.android.com/apk/res-auto"。
android:id="@ id/carView"
android:layout_width="match_parent"。
android:layout_height="90dp"。
cardView:cardCornerRadius="8dp"。
cardView:cardElevation="2dp"。
android:layout_margin="5dp"/span>>
<androidx.constraintlayout.widget.ConstraintLayout。
android:layout_width="match_parent"
android:layout_height="match_parent"/span>>
<androidx.appcompat.widget.AppCompatImageView。
android: elevation="2dp"。
android:id="@ id/imageb"
android:layout_width="50dp"。
android:layout_height="50dp"/span>
cardView:layout_constraintBottom_toBottomOf="father"
cardView:layout_constraintEnd_toEndOf="father"
cardView:layout_constraintTop_toTopOf="father"
tools:background="@drawable/ic_baseline_cloud_download_24" />
<TextView。
android:id="@ id/recording_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"。
android:layout_margin="8dp"。
android:layout_marginStart="8dp"。
android:fontFamily="sans-serif-smallcaps"
android:gravity="center_vertical"。
android:lines="2"
android:text="Title"/span>
android:padding="4dp"/span>
android:textAppearance="@style/PostTitleText"。
android:textColor="@android:color/black"
android:textSize="12sp"。
android:textStyle="bold"/span>
cardView:layout_constraintBottom_toBottomOf="father"
cardView:layout_constraintStart_toStartOf="father"
cardView:layout_constraintTop_toTopOf="father" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
uj5u.com熱心網友回復:
你在tools命名空間中使用了tools:background,這是用于設計的目的,而不是運行時的目的;所以,你會在android studio布局設計上看到圖片,但當你運行應用程式時卻看不到。
為了解決這個問題,使用android命名空間來代替:
<androidx.appcompat.widget.AppCompatImageView。
....
android:background="@drawable/ic_baseline_cloud_download_24" />
請檢查檔案以獲取更多資訊
。轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/313063.html
標籤:
