Skip to content

Instantly share code, notes, and snippets.

@gabrielemariotti
Last active January 1, 2016 07:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielemariotti/8111833 to your computer and use it in GitHub Desktop.
Save gabrielemariotti/8111833 to your computer and use it in GitHub Desktop.
Cardslib: Simple (raw and ugly) layouts for CardListView.It provides all custom layout for your list and your cards.
public class ListFragment extends Fragment {
//DAO datasource;
//List<Joke> values;
public ListFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.test_fragment_list, container, false);
return rootView;
}
public void onActivityCreated (Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayList<Card> cards = new ArrayList<Card>();
for (int i = 17; i >= 1; i--) {
final int num = i;
MyCard card = new MyCard(getActivity());
CardHeader header = new CardHeader(getActivity());
header.setTitle("Category "+i);
card.addCardHeader(header);
CardThumbnail thumb = new CardThumbnail(getActivity());
thumb.setDrawableResource(R.drawable.ic_launcher);
card.addCardThumbnail(thumb);
cards.add(card);
}
CardArrayAdapter mCardArrayAdapter = new CardArrayAdapter(getActivity(),cards);
CardListView listView = (CardListView) getView().findViewById(R.id.test_list1);
//listView.setLayout(R.layout.list_card_thumbnail_layout);
if (listView!=null){
listView.setAdapter(mCardArrayAdapter);
}
}
class MyCard extends Card{
public MyCard(Context context) {
super(context,R.layout.test_list_card_inner_layout);
}
@Override
public void setupInnerViewElements(ViewGroup parent, View view) {
TextView tx= (TextView) view.findViewById(R.id.test_card_tx1);
if (tx!=null)
tx.setText("Ok it works");
}
}
}
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_thumbnail_image"
android:scaleType="centerCrop"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Card visible layout -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/card_main_layout"
style="@style/card.main_layout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Main Content View -->
<FrameLayout
android:layout_alignParentLeft="true"
android:id="@+id/card_main_content_layout"
style="@style/card.content_outer_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<it.gmariotti.cardslib.library.view.component.CardThumbnailView
style="@style/card_thumbnail_outer_layout"
android:id="@+id/card_thumbnail_layout"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
card:card_thumbnail_layout_resourceID="@layout/test_card_image"
android:layout_height="match_parent"/>
</RelativeLayout>
<it.gmariotti.cardslib.library.view.component.CardHeaderView
style="@style/card.header_outer_layout"
android:id="@+id/card_header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<!-- Compound view for Shadow
If you want to customize this element use attr card:card_shadow_layout_resourceID -->
<it.gmariotti.cardslib.library.view.component.CardShadowView
style="@style/card.shadow_outer_layout"
android:id="@+id/card_shadow_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/card_content_expand_layout"
style="@style/card.main_contentExpand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- You can customize this layout.
You need to have in your layout a `CardView` with the ID `list_cardId` -->
<it.gmariotti.cardslib.library.view.CardListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/test_list1"
card:list_card_layout_resourceID="@layout/test_list_row_layout" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- This is the base Inner View inside a CardHeader.
You can customize it with your layout xml file and your CardHeader.
You can popolate your elements with CardHeader#setupInnerViewElements(android.view.ViewGroup, android.view.View) method -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:id="@+id/test_card_tx1"
style="@style/card.header_simple_title"/>
</LinearLayout>
<it.gmariotti.cardslib.library.view.CardView
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"
card:card_layout_resourceID="@layout/test_card_layout"
style="@style/list_card.base"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment