图像未显示在CardView中

时间:2018-11-09 17:08:25

标签: android xml

尽管预览显示了图像,但是当我在设备上运行应用程序时,图像未显示在卡视图中。

XML

 <com.google.android.material.card.MaterialCardView
    android:id="@+id/CollegesCard"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/ImportantDatesCard"
    android:layout_alignParentStart="true"
    android:layout_marginStart="15dp"
    android:layout_marginTop="13dp"
    android:elevation="10dp"
    android:padding="10dp"
    android:background="@drawable/campus"
    android:foreground="?android:attr/selectableItemBackground"
    android:clickable="true"
    android:focusable="true"
    android:stateListAnimator="@drawable/lift_on_touch">

    <RelativeLayout
        android:layout_width="170dp"
        android:layout_height="170dp"
        android:layout_gravity="center">

        <TextView
            android:id="@+id/COLLEGES"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="5dp"
            android:fontFamily="serif-monospace"
            android:text="COLLEGES"
            android:textColor="#000"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/Content"
            android:layout_width="102dp"
            android:layout_height="107dp"
            android:layout_below="@+id/COLLEGES"
            android:layout_marginStart="1dp"
            android:layout_marginTop="14dp"
            android:text="Take Admission in Top Colleges in your Location"
            android:textColor="#200094"
            android:textSize="15sp" />

        <ImageView
            android:id="@+id/CAMPUSIMAGE"
            android:layout_width="65dp"
            android:layout_height="73dp"
            android:layout_below="@+id/COLLEGES"
            android:layout_alignStart="@+id/Content"
            android:layout_marginStart="101dp"
            android:layout_marginTop="2dp"
            tools:srcCompat="@drawable/campus" />

        <ImageView
            android:layout_width="54dp"
            android:layout_height="38dp"
            android:layout_below="@id/CAMPUSIMAGE"
            android:layout_alignStart="@+id/CAMPUSIMAGE"
            android:layout_alignParentEnd="true"
            android:layout_marginStart="7dp"
            android:layout_marginTop="13dp"
            android:layout_marginEnd="14dp"
            tools:srcCompat="@drawable/ic_arrow_forward_black_24dp"
            android:scaleType="centerCrop"/>

    </RelativeLayout>

</com.google.android.material.card.MaterialCardView>

[这是虚拟设备快照的图像。1 [这是预览图像] 2

我已附上预览屏幕快照的图像和在设备上运行的应用程序。我不知道为什么未显示图像。 图像类型为.png,它是从drawable文件夹添加的。

1 个答案:

答案 0 :(得分:0)

我更改了3个视图的某些属性,请尝试:

 <com.google.android.material.card.MaterialCardView
    android:id="@+id/CollegesCard"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/ImportantDatesCard"
    android:layout_alignParentStart="true"
    android:layout_marginStart="15dp"
    android:layout_marginTop="13dp"
    android:elevation="10dp"
    android:padding="10dp"
    android:background="@drawable/campus"
    android:foreground="?android:attr/selectableItemBackground"
    android:clickable="true"
    android:focusable="true"
    android:stateListAnimator="@drawable/lift_on_touch">

    <RelativeLayout
        android:layout_width="170dp"
        android:layout_height="170dp"
        android:layout_gravity="center">

        <TextView
            android:id="@+id/COLLEGES"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="5dp"
            android:fontFamily="serif-monospace"
            android:text="COLLEGES"
            android:textColor="#000"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/Content"
            android:layout_width="102dp"
            android:layout_height="107dp"
            android:layout_below="@+id/COLLEGES"
            android:layout_marginStart="1dp"
            android:layout_marginTop="14dp"
            android:text="Take Admission in Top Colleges in your Location"
            android:textColor="#200094"
            android:textSize="15sp" />

        <ImageView
            android:id="@+id/CAMPUSIMAGE"
            android:layout_width="65dp"
            android:layout_height="73dp"
            android:layout_below="@+id/COLLEGES"
            android:layout_alignParentEnd="true"
            android:layout_toEndOf="@+id/Content"
            android:layout_marginTop="2dp"
            tools:srcCompat="@drawable/campus" />

        <ImageView
            android:layout_width="54dp"
            android:layout_height="38dp"
            android:layout_below="@id/CAMPUSIMAGE"
            android:layout_alignParentEnd="true"
            android:layout_toEndOf="@+id/Content"
            android:layout_marginStart="7dp"
            android:layout_marginTop="13dp"
            android:layout_marginEnd="14dp"
            tools:srcCompat="@drawable/ic_arrow_forward_black_24dp"
            android:scaleType="centerCrop"/>

    </RelativeLayout>
</com.google.android.material.card.MaterialCardView>