Android 12 Developer Preview is here! Try it out, and give us your feedback!

BaseCardView

public class BaseCardView
extends FrameLayout

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ androidx.leanback.widget.BaseCardView


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. 

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.

Inherited constants

Inherited fields

Public constructors

BaseCardView(Context context)
BaseCardView(Context context, AttributeSet attrs)
BaseCardView(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

BaseCardView.LayoutParams generateLayoutParams(AttributeSet attrs)
int getCardType()

Returns the type of this Card.

int getExtraVisibility()

This method is deprecated. Extra view's visibility is controlled by getInfoVisibility()

int getInfoVisibility()

Returns the visibility of the info region of the card.

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)

This method is deprecated. Extra view's visibility is controlled by setInfoVisibility(int)

void setInfoVisibility(int visibility)

Sets the visibility of the info region of the card.

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()
String toString()

Protected methods

boolean checkLayoutParams(ViewGroup.LayoutParams p)
BaseCardView.LayoutParams generateDefaultLayoutParams()
BaseCardView.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp)
int[] onCreateDrawableState(int extraSpace)
void onDetachedFromWindow()
void onLayout(boolean changed, int left, int top, int right, int bottom)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Inherited methods

Constants

CARD_REGION_VISIBLE_ACTIVATED

public static final int CARD_REGION_VISIBLE_ACTIVATED

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

Constant Value: 1 (0x00000001)

CARD_REGION_VISIBLE_ALWAYS

public static final int CARD_REGION_VISIBLE_ALWAYS

Indicates that a card region is always visible.

Constant Value: 0 (0x00000000)

CARD_REGION_VISIBLE_SELECTED

public static final int CARD_REGION_VISIBLE_SELECTED

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

Constant Value: 2 (0x00000002)

CARD_TYPE_INFO_OVER

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)

CARD_TYPE_INFO_UNDER

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)

CARD_TYPE_INFO_UNDER_WITH_EXTRA

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)

CARD_TYPE_MAIN_ONLY

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

BaseCardView

public BaseCardView (Context context)

Parameters
context Context

BaseCardView

public BaseCardView (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

BaseCardView

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

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

generateLayoutParams

public