Good day, dear colleagues. During development, there was a desire to make the list items in a similar way as Google does (rectangles with text). like here the question is how to implement? I work with Android recently, only Listview consisting of Fragment climbs into my head. Put the traveler on the right path, I will be grateful for such implementations.

  • 3
    Google CardView bib-ka - compile 'com.android.support:cardview-v7:21.0.+' - tim_taller
  • one
    Better google recycler view, it's even a bit more flexible than the listview. There you will find how to use cardview. In general, you can listview, and for the items, set the desired margin - iamthevoid
  • @tim_taller thanks! - PirateNinja

2 answers 2

1.In Layout Activity post

 <ListView android:id="@+id/lvMain" android:layout_width="match_parent" android:dividerHeight="5dp"<!--ширина разделителя--> android:layout_height="wrap_content"> </ListView> 

2. In aktivti create a variable

 ListView lvMain = (ListView) findViewById(R.id.lvMain); 

3. Create an Adapter to which the necessary values ​​will be transmitted (instead of names your array of values):

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names); 
  1. Create a Layout simple_list_item_1 and in it implement how everything should be displayed in one cell.

  2. Assign Adapter to ListView

lvMain.setAdapter(adapter);

    Hi, recently there was a development where it was necessary to use cards (CardView), yes yes it’s Google cards. So after a short search, I found this https://github.com/gabrielemariotti/cardslib

    First you download cardslib-core, then the modules you need. Create a card

     ColorCard card = new ColorCard(this.getActivity()); card.setTitle("A simple colored card " + i); 

    Create adapter

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

    Throw a card in the adapter

     ArrayList<Card> cards = new ArrayList<Card>(); cards.add(card); mCardArrayAdapter = new CardArrayAdapter(getActivity(), cards); 

    I screw the adapter to CardListView and add some animations

     mListView = (CardListView) getActivity().findViewById(R.id.carddemo_extra_list_viewanimations); AnimationAdapter animCardArrayAdapter = new AlphaInAnimationAdapter(mCardArrayAdapter); animCardArrayAdapter.setAbsListView(mListView); if (mListView != null) { mListView.setExternalAdapter(animCardArrayAdapter,mCardArrayAdapter); }