简体   繁体   中英

GridView item layout not show image

I have next GridView layout that I am inflating from their adapter. I am showing the layout and the title but I can't see the image. Anyway I see the blank space in the screen. Any idea?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="200dp">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="150dp"
        app:srcCompat="@drawable/ic_icon_normal"
        android:id="@+id/imageView" />

    <TextView
        android:text="Title of the Item"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/titleButton"
        tools:text="Title of the Item"
        android:textAlignment="center"
        android:gravity="center_vertical" />

</LinearLayout>

Do you have added AppCompat library in gradle:

compile 'com.android.support:appcompat-v7:25.0.0'

Becuase app:srcCompat attribute is actually defined within AppCompat library .

You can use tools:ignore="MissingPrefix" to avoid seeing error temporarily.

<android.support.v7.widget.AppCompatImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    app:srcCompat="@drawable/ic_icon_normal"
    tools:ignore="MissingPrefix"/>

Try to use AppCompatImageView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM