Cardslib Thumbnail not appearing

412 views Asked by At

I'm experimenting with the Android cardslib and trying to show an image using this tutorial: https://github.com/gabrielemariotti/cardslib/blob/master/doc/THUMBNAIL.md

However, it doesn't show the image, just an empty card.

My Activity code is:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Create a Card
    Card card = new Card(this);

    //Create thumbnail
    CardThumbnail thumb = new CardThumbnail(this);

    //Set URL resource
    thumb.setUrlResource("https://lh5.googleusercontent.com/-N8bz9q4Kz0I/AAAAAAAAAAI/AAAAAAAAAAs/Icl2bQMyK7c/s265-c-k-no/photo.jpg");

    //Add thumbnail to a card
    card.addCardThumbnail(thumb);

    //Set card in the cardView
    CardViewNative cardView = (CardViewNative) this.findViewById(R.id.carddemo);
    cardView.setCard(card);
}

I have also tried doing this from a local resource, like this:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 //Create a Card
    Card card = new Card(this);

    //Create thumbnail
    CardThumbnail thumb = new CardThumbnail(this);

    //Set ID resource
    thumb.setDrawableResource(R.drawable.ic_launcher);

    //Add thumbnail to a card
    card.addCardThumbnail(thumb);

    //Set card in the cardView
    CardViewNative cardView = (CardViewNative) this.findViewById(R.id.carddemo);
    cardView.setCard(card);

My XML is:

<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<it.gmariotti.cardslib.library.view.CardViewNative
    android:id="@+id/carddemo"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:layout_marginTop="12dp"/>

<it.gmariotti.cardslib.library.view.CardViewNative
    card_layout_resourceID="@layout/native_card_thumbnail_layout"
    android:layout_below="@id/carddemo"
    android:id="@+id/carddemo_thumb_url"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

What am I doing wrong? Why won't my images load? It doesn't seem to matter which card I point it at in my XML file, either carddemo or carddemo_thumb_url, either one doesn't seem to work. Thanks in advance!

1

There are 1 answers

1
Gabriele Mariotti On BEST ANSWER

You have to use a card layout where there is a CardThumbnailView.

For example check this layout:

To use a custom layout you have to use the attribute: card:card_layout_resourceID (you have to use a custom namespace)

   <it.gmariotti.cardslib.library.view.CardViewNative
         card:card_layout_resourceID="@layout/native_card_thumbnail_layout" />