Search code examples
androidandroid-layoutandroid-cardviewcardslib

Cardslib round corners


I have two projects where I create a set of custom cards extending the card class, and then I insert them into a StaggeredView.

My problem is that in one of these projects the cards corners are automatically rounded, while on the other one not!

Moreover in the second project the scroll occurs in fits and starts!

Here's my code:

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

    List<Tour> data = createList(10);

    ArrayList<Card> cardes = initCards(data);

    mCardArrayAdapter = new CardGridStaggeredArrayAdapter(ListViewPrenota.this, cardes);

    CardGridStaggeredView mGridView = (CardGridStaggeredView)
            ListViewPrenota.this.findViewById(R.id.carddemo_extras_grid_stag);

    if (mGridView != null) {
        mGridView.setAdapter(mCardArrayAdapter);
    }
}


private ArrayList<Card> initCards(List<Tour> data){

    ArrayList<Card> cards = new ArrayList<>();
    for(int i = 0; i <= data.size()-1; i++ ){
        DeviceCardList card = new DeviceCardList(this, R.layout.cardslib_inner_layout, data.get(i));

        cards.add(card);
    }
    return cards;
}

DeviceCardList: class

cardslib_inner_layout: xml file

staggered_view.xml: xml file


Solution

  • Solved it! It turns out that in order to set the cards' corners with cardslib, it is necessary to OVERRIDE this value:

    <dimen name="cardview_default_radius">yourRadius</dimen>
    <dimen name="card_background_default_radius">"yourRadius"</dimen>
    

    from this file: dimens.xml

    For me it was only necessary to override card_background_default_radius