gabrielemariotti / cardslib

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

CardGridView, the thumbnail not show images #263

Open zzMOM opened 10 years ago

zzMOM commented 10 years ago

I try to use CardGridView, but the thumbnail not show images. I also try CardListView, it works; but CardGridView not. Can you please help to check what's the problem. Thanks a lot.

xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.babydays.MainMenuCard"
    xmlns:card="http://schemas.android.com/apk/res-auto" >

<it.gmariotti.cardslib.library.view.CardGridView
          android:id="@+id/cardGridMenu"
          android:layout_above="@id/ll"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:columnWidth="150dp"
          android:numColumns="auto_fit"
          android:verticalSpacing="3dp"
          android:horizontalSpacing="2dp"
          android:stretchMode="columnWidth"
          android:gravity="center"
          card:list_card_layout_resourceID="@layout/list_card_thumbnail_layout"/>

</RelativeLayout>

java

public class MainMenuCard extends Activity {
        static final String[] items = new String[]{"Feed", "Nap", "Diaper", "Milestone", "Diary"};
    static final Integer[] imageId = {  R.drawable.bottle,
                                        R.drawable.sleep,
                                        R.drawable.diaper,
                                        R.drawable.milestones,
                                        R.drawable.diary};

    private CardGridView cardGridMenu;

        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_menu_card);

                cardGridMenu = (CardGridView) findViewById(R.id.cardGridMenu);
        //create Card list
        ArrayList<Card> cards = new ArrayList<Card>();
        for(int i = 0; i < items.length; i++){
            Card c = new Card(this);
            //add header
            CardHeader cheader = new CardHeader(this);
            cheader.setTitle(items[i]);
            c.addCardHeader(cheader);
            //add card thumb nail
            CardThumbnail thumb = new CardThumbnail(this);
            thumb.setDrawableResource(imageId[i]);
            c.addCardThumbnail(thumb);

            cards.add(c);
        }
        CardArrayAdapter cardAdapter = new CardArrayAdapter(this, cards);
        cardGridMenu.setAdapter(cardAdapter);
    }
gabrielemariotti commented 10 years ago

Can you post a screenshot?

zzMOM commented 10 years ago

device-2014-08-26-140124

zzMOM commented 10 years ago

If I change to CardListView, it will be right. So why CardGridView not works. Thanks for help.

device-2014-08-26-140524

zzMOM commented 10 years ago

Hi Gabriele, I try this example. http://java.dzone.com/articles/be-lazy-productive-android-2 https://github.com/PareshMayani/CardslibDemo

    It works using CardListView, but if I change to CardGridView, the images will not show. The same problems as mine.
vignesh-s commented 9 years ago

i am also having the same problem now thumbnail not displaying in GridView help please