3 Star 0 Fork 0

Gitee 极速下载 / cardslib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/gabrielemariotti/cardslib
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CARDRECYCLERVIEW.md 5.21 KB
一键复制 编辑 原始数据 按行查看 历史

Cards Library: CardRecyclerView

In this page you can find info about:

Intro

PAY ATTENTION: to use this feature you have to use the library-recyclerview. for more info.

Creating a base CardRecyclerView

Creating a CardRecyclerView is pretty simple.

First, you need an XML layout that will display the CardRecyclerView.

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

Then create an Array of Cards:

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

      //Create a Card
      Card card = new Card(getContext());

      //Create a CardHeader
      CardHeader header = new CardHeader(getContext());
      ....
      //Add Header to card
      card.addCardHeader(header);

      cards.add(card);

Last create a CardArrayAdapter, get a reference to the CardListView from your code and set your adapter.

        CardArrayRecyclerViewAdapter mCardArrayAdapter = new CardArrayRecyclerViewAdapter(getActivity(), cards);

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

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

This CardRecyclerView uses for each row the row-list layout:

Use your custom layout for each row

Card Library provides 2 built-in row-list layouts.

For the CardViewNative:

For the CardView:

You can customize the layout used for each item in the RecyclerView using the attr: card:list_card_layout_resourceID="@layout/my_layout

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

In your row-list layout you can use your CardViewNative with all its features and its possibilities. Example native_recyclerview_card_thumbnail_layout.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_card_layout"/>

You can build your layout, but need to have:

  1. a CardViewNative or CardView with the ID list_cardId

Screen

Style

You can customize some properties with your style and drawable files. The quickest way to start with this would be to copy the specific style or drawable in your project and change them.

For the CardViewNative:

These are the main style properties:

  • native_recyclerview_card: common style applied to the single card item
  • native_recyclerview_card.base: style applied for base layout
  • native_recyclerview_card.thumbnail: style applied for thumbnail layout

margins:

    <dimen name="native_recyclerview_card_margin_left">0dp</dimen>
    <dimen name="native_recyclerview_card_margin_right">0dp</dimen>
    <dimen name="native_recyclerview_card_margin_bottom">4dp</dimen>
    <dimen name="native_recyclerview_card_margin_top">4dp</dimen>

For the CardView:

These are the main style properties:

  • list_card: common style applied to the single card item
  • list_card.base: style applied for base layout
  • list_card.thumbnail: style applied for thumbnail layout

margins:

    <dimen name="list_card_padding_left">8dp</dimen>
    <dimen name="list_card_padding_right">8dp</dimen>
    <dimen name="list_card_padding_bottom">6dp</dimen>
    <dimen name="list_card_padding_top">2dp</dimen>
Java
1
https://gitee.com/mirrors/cardslib.git
git@gitee.com:mirrors/cardslib.git
mirrors
cardslib
cardslib
master

搜索帮助