2014-12-21 35 views
2

我與Android cardslib實驗和嘗試使用本教程中顯示的圖像:https://github.com/gabrielemariotti/cardslib/blob/master/doc/THUMBNAIL.mdCardslib縮略圖沒有出現

但是,它不顯示圖像,只是一個空卡。

我的動態代碼是:

@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); 
} 

我也試圖從當地的資源做這個,像這樣:

@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); 

我的XML是:

<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" /> 

我在做什麼錯?爲什麼我的圖片無法加載?在我的XML文件中指向哪張卡,無論是carddemo還是carddemo_thumb_url,似乎都不起作用。提前致謝!

回答

1

你必須使用一個卡布局,其中有一個CardThumbnailView.

例如檢查這個layoutcard:card_layout_resourceID(你必須使用一個自定義的:

要使用你必須使用屬性自定義佈局命名空間)

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

我覺得這是我正在做的事情,但是當我有時間並且回覆你時,我會看一看。感謝您的回答。 – Dwebtron