We'll make a CoverView
for reuse in the list view screens as well as the view at the top of the detail screen.
Android's custom view training and the API guide gives you a good start, but stops short of actually implementing the custom view.
Tip: I often create a blank project to work on complex UI components. Working this way reduces the clutter of networking, DB interactions, etc. After I perfect it, it gets copied into my main project.
cover_view_attr.xml
in the values
folder. Create an attribute called showRatingBar
that takes a boolean
and another called placeHolder
that takes a resource
. We will add more attributes later. This is not a well documented feature of Android, here's a decent reference and the source.CoverView
. Choose a sensible base class.<merge>
tag as the base element in the view.showRatingBar
and placeHolder
attributes so that users can create an instance of your view either with XML or in code.RoboAttributeSet
. Clues here, here, and here. I also asked a stackoverflow question: http://stackoverflow.com/questions/24999471/how-do-i-configure-roboattributeset-for-a-custom-view-in-robolectric.Add custom attributes for textColor
, textPosition
, textBgColor
, and pinAnimation
. React to these attributes in your view. We'll use the pin animation value when we cover animations.