Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 35  Material Design


Once you do that, you can use CardView like any other ViewGroup in a layout. It is a FrameLayout
subclass, so you can use any of FrameLayout’s layout params for CardView’s children.


Listing 35.9  Using CardView in a layout


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.v7.widget.CardView
android:id="@+id/item"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="16dp"



...





Because CardView is a support library class, it gives you some nice compatibility features on older
devices. Unlike other widgets, it will always project a shadow. (On older versions, it will simply draw
its own – not a perfect shadow, but close enough.) See CardView’s documentation for other minor
visual differences, if you are interested.

Free download pdf