5

Sto implementando la nuova scheda Material Design dalla libreria Cardslib di Github. Link Library: Cardslib Github Ma non sono in grado di implementare più schede all'interno della visualizzazione Recycler. Sarebbe molto utile se qualcuno avesse già implementato la nuova libreria di Cardslib v2.Scheda materiale con libreria Cardslib

Il problema è che le carte stanno arrivando ma quelle non hanno l'immagine di sfondo e pulsanti di azione.

Il layout Carta che sto cercando di realizzare è:

Card Layout

Qui è il codice per RecyclerView

<it.gmariotti.cardslib.library.recyclerview.view.CardRecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:paddingTop="10dp" 
     card:list_card_layout_resourceID="@layout/native_recyclerview_card_layout" 
     android:id="@+id/card_recyclerview"/> 

ecco il codice per l'attività

public class AboutActivity extends ActionBarActivity { 


    final int TOTAL_CARDS = 3; 
    //private CardArrayAdapter 
    private CardArrayRecyclerViewAdapter mCardArrayAdapter; 
    private CardRecyclerView mRecyclerView; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.about_activity); 
     ArrayList<Card> cards = new ArrayList<>(); 

     mCardArrayAdapter = new CardArrayRecyclerViewAdapter(this, cards); 

     //Staggered grid view 
     CardRecyclerView mRecyclerView = (CardRecyclerView) findViewById(R.id.card_recyclerview); 
     mRecyclerView.setHasFixedSize(false); 
     mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); 

     //Set the empty view 
     if (mRecyclerView != null) { 
      mRecyclerView.setAdapter(mCardArrayAdapter); 
     } 

     //Load cards 
     new LoaderAsyncTask().execute(); 
    } 

    private ArrayList<Card> initCard() { 

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

     for (int i = 0; i < TOTAL_CARDS; i++) { 


      MaterialLargeImageCard card = new MaterialLargeImageCard(this); 
      //card.setInnerLayout(R.layout.native_material_largeimage_text_card); 
      card.setTextOverImage("Italian Beaches"); 
      card.setDrawableIdCardThumbnail(R.drawable.card_background_01); 

      //Set the title and subtitle in the card 
      card.setTitle("This is my favorite local beach"); 
      card.setSubTitle("A wonderful place"); 

      // Set supplemental actions 
      TextSupplementalAction t1 = new TextSupplementalAction(this, R.id.action1); 
      t1.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() { 
       @Override 
       public void onClick(Card card, View view) { 
        Toast.makeText(AboutActivity.this, " Click on Text SHARE ", Toast.LENGTH_SHORT).show(); 
       } 
      }); 
      card.addSupplementalAction(t1); 

      //Set the layout for supplemental actions 
      card.setLayout_supplemental_actions_id(R.layout.about_card_supplemental_actions); 

      //Very important call: build the card 
      card.build(); 
      cards.add(card); 

     } 

     return cards; 
    } 

    private void updateAdapter(ArrayList<Card> cards) { 
     if (cards != null) { 
      mCardArrayAdapter.addAll(cards); 
     } 
    } 

    class LoaderAsyncTask extends AsyncTask<Void, Void, ArrayList<Card>> { 

     LoaderAsyncTask() { 
     } 

     @Override 
     protected ArrayList<Card> doInBackground(Void... params) { 
      //elaborate images 
      //SystemClock.sleep(1000); //delay to simulate download, don't use it in a real app 

      ArrayList<Card> cards = initCard(); 
      return cards; 

     } 

     @Override 
     protected void onPostExecute(ArrayList<Card> cards) { 
      //Update the adapter 
      updateAdapter(cards); 
      //displayList(); 
     } 
    } 
} 

AGGIORNAMENTO:

material_card.xml:

<it.gmariotti.cardslib.library.view.CardViewNative 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/list_cardId" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    style="@style/native_recyclerview_card.base" 
    card:card_layout_resourceID="@layout/native_material_largeimage_text_card"/> 

Nella layout XML:

<it.gmariotti.cardslib.library.recyclerview.view.CardRecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/myCardList" 
     card:list_card_layout_resourceID="@layout/material_card" /> 

all'interno per ciclo:

ArrayList<BaseSupplementalAction> actions = new ArrayList<BaseSupplementalAction>(); 

      // Set supplemental actions 
      TextSupplementalAction t1 = new TextSupplementalAction(this, R.id.action1); 
      t1.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() { 
       @Override 
       public void onClick(Card card, View view) { 
        Toast.makeText(AboutActivity.this," Click on Text SHARE "+card.getTitle(),Toast.LENGTH_SHORT).show(); 
       } 
      }); 
      actions.add(t1); 



      //Create a Card, set the title over the image and set the thumbnail 
      MaterialLargeImageCard card = 
        MaterialLargeImageCard.with(this) 
          .setTextOverImage("Italian Beaches "+i) 
          .setTitle("This is my favorite local beach "+i) 
          .setSubTitle("A wonderful place") 
          .useDrawableId(R.drawable.card_background_01) 
          .setupSupplementalActions(R.layout.about_card_supplemental_actions, actions) 
          .build(); 

      card.setOnClickListener(new Card.OnCardClickListener() { 
       @Override 
       public void onClick(Card card, View view) { 
        Toast.makeText(AboutActivity.this," Click on ActionArea ",Toast.LENGTH_SHORT).show(); 
       } 
      }); 

      card.build(); 
      cards.add(card); 

UPDATE 2

Dopo aver fatto alcuni esperimenti Sto pensando che questo potrebbe essere il colpevole

<it.gmariotti.cardslib.library.recyclerview.view.CardRecyclerView 
     android:id="@+id/myCardList" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingTop="10dp" 
     card:list_card_layout_resourceID="@layout/material_card" /> 

Qui anche se cambio titolo material_card a qualcos'altro si compila bene. Penso che "card: list_card_layout_resourceID =" @ layout/material_card "" non venga in qualche modo attivato.

UPDATE 3

Infine risolto. Il problema era nella dichiarazione xml. Per errore l'ho copiato male. xmlns: card = "http://schemas.android.com/apk/res-auto" è corretto uno

Grazie mille per l'aiuto @Gabriele. Questa libreria rocce appena :)

+0

Simplycity utilizzerà la nuova scheda di memoria da google! facile da implementare! –

+0

@twntee Yaa ma questa libreria è troppo interessante per essere ignorata. Sto usando sin dalla v1.7 –

+0

tempo per guardare avanti amico! –

risposta

4

Si può trovare un esempio qui:

https://github.com/gabrielemariotti/cardslib/blob/dev/demo/stock/src/main/java/it/gmariotti/cardslib/demo/fragment/nativeview/NativeRecyclerViewMaterialCardFragment.java

Il tuo problema è il layout. tuo RecyclerView utilizzare questo layout della carta: carta: list_card_layout_resourceID = "@ Layout/native_recyclerview_card_layout"

è necessario utilizzare un layout di scheda con il material_card_layout.

Esempio (il layout utilizzato nell'esempio di cui sopra): https://github.com/gabrielemariotti/cardslib/blob/dev/demo/stock/src/main/res/layout/native_recyclerview_material_card_layout.xml

Inoltre vi consiglio di utilizzare il costruttore al posto del costruttore standard per la vostra scheda.

Fare attenzione. C'è un bug che sto investigando: https://github.com/gabrielemariotti/cardslib/issues/361

+0

Ho aggiornato le modifiche ma non riesco ancora a visualizzare le schede dei materiali. Posso vedere solo le carte base. Ho aggiornato le modifiche apportate alle modifiche. Qualcosa che sto facendo male? Grazie mille per l'aiuto. –

+0

Forse il colpevole è la carta: list_card_layout_resourceID = "@ layout/material_card". Si prega di dare un'occhiata all'aggiornamento 2. –

+2

Risolto il problema. Aggiornato il post. Grazie mille :) –

Problemi correlati