gabrielemariotti / cardslib

Android Library to build a UI Card
4.66k stars 1.19k forks source link

CardListView don't display images #484

Open dzordz55 opened 9 years ago

dzordz55 commented 9 years ago

I have a problem with displaying images in CardListView. Cards looks like below:

screenshot_2015-07-17-15-34-45

This is my layout with CardListView. If it's important, layout is in SlidingUpPanelLayout view from https://github.com/umano/AndroidSlidingUpPanel

<it.gmariotti.cardslib.library.view.CardListView
        android:id="@+id/cardlistview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        style="@style/list_card.thumbnail"
        card:list_card_layout_resourceID="@layout/list_card_thumbnail_layout" />

My custom card layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:padding="10dp" >

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/card_thumbnail_image"/>

<TextView
    android:id="@+id/card_main_inner_simple_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/card_main_inner_secondary_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Cardslib"
    android:textAppearance="?android:attr/textAppearanceMedium" />

And code where I add images:

ArrayList<Card> cards = new ArrayList<>();

    for(int i = 0; i < data.size(); i++)
    {
        Card card = new Card(getActivity(), R.layout.card_layout);
        card.setBackgroundColorResourceId(R.color.colorCard);

        CardThumbnail thumb = new CardThumbnail(getActivity());
        thumb.setDrawableResource(R.drawable.ic_delete);

        card.addCardThumbnail(thumb);
        cards.add(card);
    }

    CardArrayAdapter cardArrayAdapter = new CardArrayAdapter(getActivity(), cards);
    CardListView listView = (CardListView) getView().findViewById(R.id.cardlistview);
    if (listView != null)
        listView.setAdapter(cardArrayAdapter);

    cardArrayAdapter.notifyDataSetChanged();
safakadir commented 9 years ago

I got the same problem once. I overcame this by using CardRecyclerView instead of CardListView.