ImageView没有';t正在开发android应用程序的CardView
我正在学习在android studio上为android做一个应用程序,我被一个问题绊住了。 我在CardView上添加了ImageView。在预览时我可以看到ImageView,但在构建时我看不到。如何修复它 XML代码:ImageView没有';t正在开发android应用程序的CardView,android,android-studio,android-imageview,android-cardview,Android,Android Studio,Android Imageview,Android Cardview,我正在学习在android studio上为android做一个应用程序,我被一个问题绊住了。 我在CardView上添加了ImageView。在预览时我可以看到ImageView,但在构建时我看不到。如何修复它 XML代码: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.c
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.49"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.51">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/cardView2"
android:layout_width="393dp"
android:layout_height="118dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/cardView"
app:layout_constraintTop_toBottomOf="@+id/cardView">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:layout_marginEnd="220dp"
android:adjustViewBounds="true"
android:contentDescription="@string/da"
android:cropToPadding="true"
android:scaleType="fitXY"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/backgrounds/scenic[15]" />
<TextView
android:id="@+id/textView9"
android:layout_width="210dp"
android:layout_height="99dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:fontFamily="serif"
android:text="@string/tri"
android:textColor="@android:color/background_dark"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.28"
app:layout_constraintStart_toEndOf="@+id/imageView4"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.65999997" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="385dp"
android:layout_height="134dp"
app:layout_constraintBottom_toTopOf="@+id/cardView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.48000002">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView8"
android:layout_width="249dp"
android:layout_height="109dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:fontFamily="serif"
android:text="@string/b"
android:textAlignment="viewStart"
android:textColor="@android:color/background_dark"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="@+id/imageView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/imageView3"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.666" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/da"
android:cropToPadding="true"
android:scaleType="fitXY"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/textView8"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars[0]" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
我所拥有的
如果这是一个愚蠢的问题,很抱歉,但我在谷歌找不到解决方案
tools:srcCompat="@tools:sample/backgrounds/scenic[15]"
对此:
app:srcCompat="@tools:sample/backgrounds/scenic[15]"
实际上,添加一个不同的drawable,因为这些化身仅用于示例版本,而不用于构建版本
避免这种情况
AAPT:错误:“@tools:sample/avatars”与属性srcCompat(attr)reference[弱]不兼容
使用可拉伸的
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/imageView"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:srcCompat="@drawable/ic_logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
做这个
tools:srcCompat="@tools:sample/backgrounds/scenic[15]"
对此:
app:srcCompat="@tools:sample/backgrounds/scenic[15]"
实际上,添加一个不同的drawable,因为这些化身仅用于示例版本,而不用于构建版本
避免这种情况
AAPT:错误:“@tools:sample/avatars”与属性srcCompat(attr)reference[弱]不兼容
使用可拉伸的
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/imageView"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:srcCompat="@drawable/ic_logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
对您的imageview执行此操作
android:src="@drawable/image"
将图像放入res/drawable
对图像视图执行此操作
android:src="@drawable/image"
将图像放入res/drawable