Life of Apps

CardView Basics

The new version of Google apps such as Google Now and Google News all use cards in their UI.

    Google Now

    Google News

Behind the scenes, it is CardView at work. CardView is part of the android support library and is being used extensively with RecyclerView as a replacement for the ListView.
Just like you would define a list item, you define a cardview in its own xml file such as list_item.xml. The CardView can include Imageviews and Textviews inside a linearlayout. To provide a card-like to the component, CardView includes the following attributes:

app:cardCornerRadius="10sp"app:cardElevation="2sp"app:cardBackgroundColor="#ffffff"app:cardUseCompatPadding="true"

The cardCornerRadius provides for a rounded view for the cards, like rounded rectangles. The cardElevation gives a 3D look to the cards. The cardUseCompatPadding provides uniform padding for the cards across platforms (Lollipop and others).

As with any other UI component, CardView can be added using the findViewById method

View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.main_view_row, parent, false);

If you are using this with RecyclerView, the CardView will be typically added inside the RecyclerView adapter's onCreateViewHolder method.

Danesh

Visit Pleb.in for apps developed by Danesh

No comments :

Post a Comment

Leave a Comment...