Android APIs
public class

BaseCardView

extends ViewGroup
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.v17.leanback.widget.BaseCardView
Known Direct Subclasses

Class Overview

A card style layout that responds to certain state changes. It arranges its children in a vertical column, with different regions becoming visible at different times.

A BaseCardView will draw its children based on its type, the region visibilities of the child types, and the state of the widget. A child may be marked as belonging to one of three regions: main, info, or extra. The main region is always visible, while the info and extra regions can be set to display based on the activated or selected state of the View. The card states are set by calling setActivated and setSelected.

See BaseCardView.LayoutParams for layout attributes.

Summary

Nested Classes
class BaseCardView.LayoutParams Per-child layout information associated with BaseCardView. 
[Expand]
Inherited XML Attributes
From class android.view.ViewGroup
From class android.view.View
Constants
int CARD_REGION_VISIBLE_ACTIVATED Indicates that a card region is visible when the card is activated.
int CARD_REGION_VISIBLE_ALWAYS Indicates that a card region is always visible.
int CARD_REGION_VISIBLE_SELECTED Indicates that a card region is visible when the card is selected.
int CARD_TYPE_INFO_OVER A Card type with 2 layout areas: A main area which is always visible, and an info area that fades in over the main area when it is visible.
int CARD_TYPE_INFO_UNDER A Card type with 2 layout areas: A main area which is always visible, and an info area that appears below the main area.
int CARD_TYPE_INFO_UNDER_WITH_EXTRA A Card type with 3 layout areas: A main area which is always visible; an info area which will appear below the main area, and an extra area that only appears after a short delay.
int CARD_TYPE_MAIN_ONLY A simple card type with a single layout area.
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
BaseCardView(Context context)
BaseCardView(Context context, AttributeSet attrs)
BaseCardView(Context context, AttributeSet attrs, int defStyle)
Public Methods
BaseCardView.LayoutParams generateLayoutParams(AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set.
int getCardType()
Returns the type of this Card.
int getExtraVisibility()
int getInfoVisibility()
boolean isSelectedAnimationDelayed()
Returns a boolean indicating if the selected animation will run immediately or be delayed the next time the card is Selected.
void setActivated(boolean activated)
Sets the Activated state of this Card.
void setCardType(int type)
Sets the type of this Card.
void setExtraVisibility(int visibility)
void setInfoVisibility(int visibility)
void setSelected(boolean selected)
Sets the Selected state of this Card.
void setSelectedAnimationDelayed(boolean delay)
Sets a flag indicating if the Selected animation (if the selected card type implements one) should run immediately after the card is selected, or if it should be delayed.
boolean shouldDelayChildPressedState()
Return true if the pressed state should be delayed for children or descendants of this ViewGroup.
String toString()
Returns a string containing a concise, human-readable description of this object.
Protected Methods
boolean checkLayoutParams(ViewGroup.LayoutParams p)
BaseCardView.LayoutParams generateDefaultLayoutParams()
Returns a set of default layout parameters.
BaseCardView.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp)
Returns a safe set of layout parameters based on the supplied layout params.
void onDetachedFromWindow()
This is called when the view is detached from a window.
void onLayout(boolean changed, int left, int top, int right, int bottom)
Called from layout when this view should assign a size and position to each of its children.
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

[Expand]
Inherited Methods
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Constants

public static final int CARD_REGION_VISIBLE_ACTIVATED

Indicates that a card region is visible when the card is activated.

Constant Value: 1 (0x00000001)

public static final int CARD_REGION_VISIBLE_ALWAYS

Indicates that a card region is always visible.

Constant Value: 0 (0x00000000)

public static final int CARD_REGION_VISIBLE_SELECTED

Indicates that a card region is visible when the card is selected.

Constant Value: 2 (0x00000002)

public static final int CARD_TYPE_INFO_OVER

A Card type with 2 layout areas: A main area which is always visible, and an info area that fades in over the main area when it is visible. The card height will not change.

See Also
Constant Value: 1 (0x00000001)

public static final int CARD_TYPE_INFO_UNDER

A Card type with 2 layout areas: A main area which is always visible, and an info area that appears below the main area. When the info area is visible the total card height will change.

See Also
Constant Value: 2 (0x00000002)

public static final int CARD_TYPE_INFO_UNDER_WITH_EXTRA

A Card type with 3 layout areas: A main area which is always visible; an info area which will appear below the main area, and an extra area that only appears after a short delay. The info area appears below the main area, causing the total card height to change. The extra area animates in at the bottom of the card, shifting up the info view without affecting the card height.

See Also
Constant Value: 3 (0x00000003)

public static final int CARD_TYPE_MAIN_ONLY

A simple card type with a single layout area. This card type does not change its layout or size as it transitions between Activated/Not-Activated or Selected/Unselected states.

See Also
Constant Value: 0 (0x00000000)

Public Constructors

public BaseCardView (Context context)

public BaseCardView (Context context, AttributeSet attrs)

public BaseCardView (Context context, AttributeSet attrs, int defStyle)

Public Methods

public BaseCardView.LayoutParams generateLayoutParams (AttributeSet attrs)

Returns a new set of layout parameters based on the supplied attributes set.

Parameters
attrs the attributes to build the layout parameters from
Returns

public int getCardType ()

Returns the type of this Card.

Returns
  • The type of this card.

public int getExtraVisibility ()

public int getInfoVisibility ()

public boolean isSelectedAnimationDelayed ()

Returns a boolean indicating if the selected animation will run immediately or be delayed the next time the card is Selected.

Returns
  • true if this card is set to delay the selected animation the next time it is selected, or false if the selected animation will run immediately the next time the card is selected.

public void setActivated (boolean activated)

Sets the Activated state of this Card. This can trigger changes in the card layout, resulting in views to become visible or hidden. A card is normally set to Activated state when its parent container (like a Row) receives focus, and then activates all of its children.

Parameters
activated True if the card is ACTIVE, or false if INACTIVE.
See Also

public void setCardType (int type)

Sets the type of this Card.

Parameters
type The desired card type.

public void setExtraVisibility (int visibility)

public void setInfoVisibility (int visibility)

public void setSelected (boolean selected)

Sets the Selected state of this Card. This can trigger changes in the card layout, resulting in views to become visible or hidden. A card is normally set to Selected state when it receives input focus.

Parameters
selected True if the card is Selected, or false otherwise.
See Also

public void setSelectedAnimationDelayed (boolean delay)

Sets a flag indicating if the Selected animation (if the selected card type implements one) should run immediately after the card is selected, or if it should be delayed. The default behavior is to delay this animation. This is a one-shot override. If set to false, after the card is selected and the selected animation is triggered, this flag is automatically reset to true. This is useful when you want to change the default behavior, and have the selected animation run immediately. One such case could be when focus moves from one row to the other, when instead of delaying the selected animation until the user pauses on a card, it may be desirable to trigger the animation for that card immediately.

Parameters
delay True (default) if the selected animation should be delayed after the card is selected, or false if the animation should run immediately the next time the card is Selected.

public boolean shouldDelayChildPressedState ()

Return true if the pressed state should be delayed for children or descendants of this ViewGroup. Generally, this should be done for containers that can scroll, such as a List. This prevents the pressed state from appearing when the user is actually trying to scroll the content. The default implementation returns true for compatibility reasons. Subclasses that do not scroll should generally override this method and return false.

public String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

Protected Methods

protected boolean checkLayoutParams (ViewGroup.LayoutParams p)

protected BaseCardView.LayoutParams generateDefaultLayoutParams ()

Returns a set of default layout parameters. These parameters are requested when the View passed to addView(View) has no layout parameters already set. If null is returned, an exception is thrown from addView.

Returns
  • a set of default layout parameters or null

protected BaseCardView.LayoutParams generateLayoutParams (ViewGroup.LayoutParams lp)

Returns a safe set of layout parameters based on the supplied layout params. When a ViewGroup is passed a View whose layout params do not pass the test of checkLayoutParams(android.view.ViewGroup.LayoutParams), this method is invoked. This method should return a new set of layout params suitable for this ViewGroup, possibly by copying the appropriate attributes from the specified set of layout params.

Parameters
lp The layout parameters to convert into a suitable set of layout parameters for this ViewGroup.
Returns

protected void onDetachedFromWindow ()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.

protected void onLayout (boolean changed, int left, int top, int right, int bottom)

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed This is a new size or position for this view
left Left position, relative to parent
top Top position, relative to parent
right Right position, relative to parent
bottom Bottom position, relative to parent

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.