ImageCardView


public class ImageCardView extends BaseCardView


A subclass of BaseCardView with an ImageView as its main region. The ImageCardView is highly customizable and can be used for various use-cases by adjusting the ImageViewCard's type to any combination of Title, Content, Badge or ImageOnly.

Styling

There are two different ways to style the ImageCardView. No matter what way you use, all your styles applied to an ImageCardView have to extend the style Widget_Leanback_ImageCardViewStyle.

Example:

<style name="CustomImageCardViewStyle" parent="Widget.Leanback.ImageCardViewStyle">
        <item name="cardBackground">#F0F</item>
        <item name="lbImageCardViewType">Title|Content</item>
   </style>
   <style name="CustomImageCardTheme" parent="Theme.Leanback">
        <item name="imageCardViewStyle">@style/CustomImageCardViewStyle</item>
        <item name="imageCardViewInfoAreaStyle">@style/ImageCardViewColoredInfoArea</item>
        <item name="imageCardViewTitleStyle">@style/ImageCardViewColoredTitle</item>
    </style>

The first possibility is to set custom Styles in the Leanback Theme's attributes imageCardViewStyle, imageCardViewTitleStyle etc. The styles set here, is the default style for all ImageCardViews.

The second possibility allows you to style a particular ImageCardView. This is useful if you want to create multiple types of cards. E.g. you might want to display a card with only a title and another one with title and content. Thus you need to define two different ImageCardViewStyles and two different themes and apply them to the ImageCardViews. You can do this by using a the ImageCardView constructor and passing a ContextThemeWrapper with the custom ImageCardView theme id.

Example (using constructor):

    new ImageCardView(new ContextThemeWrapper(context, R.style.CustomImageCardTheme));

You can style all ImageCardView's components such as the title, content, badge, infoArea and the image itself by extending the corresponding style and overriding the specific attribute in your custom ImageCardView theme.

Components

The ImageCardView contains three components which can be combined in any combination:
  • Title: The card's title
  • Content: A short description
  • Badge: An icon which can be displayed on the right or left side of the card.
In order to choose the components you want to use in your ImageCardView, you have to specify them in the lbImageCardViewType attribute of your custom ImageCardViewStyle. You can combine the following values: Title, Content, IconOnRight, IconOnLeft, ImageOnly.

Examples:

<style name="CustomImageCardViewStyle" parent="Widget.Leanback.ImageCardViewStyle">
        ...
        <item name="lbImageCardViewType">Title|Content|IconOnLeft</item>
        ...
    </style>
<style name="CustomImageCardViewStyle" parent="Widget.Leanback.ImageCardViewStyle">
        ...
        <item name="lbImageCardViewType">ImageOnly</item>
        ...
    </style>
imageCardViewStylelbImageCardViewTypeimageCardViewTitleStyleimageCardViewContentStyleimageCardViewBadgeStyleimageCardViewImageStyleimageCardViewInfoAreaStyle

Summary

Constants

static final int
static final int
static final int
static final int
static final int

Public constructors

ImageCardView(Context context, int themeResId)

This method is deprecated.

Calling this constructor inefficiently creates one ContextThemeWrapper per card, you should share it in card Presenter: wrapper = new ContextThemeWrapper(context, themResId); return new ImageCardView(wrapper);

ImageCardView(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)

Public methods

@Nullable Drawable

Returns the badge image drawable.

@Nullable CharSequence

Returns the content text.

@Nullable Drawable

Returns the info area background drawable.

@Nullable Drawable

Returns the ImageView drawable.

final @Nullable ImageView

Returns the main image view.

@Nullable CharSequence

Returns the title text.

boolean
void

Sets the badge image drawable.

void

Sets the content text.

void

Sets the info area background drawable.

void

Sets the info area background color.

void

Sets the image drawable with fade-in animation.

void
setMainImage(@Nullable Drawable drawable, boolean fade)

Sets the image drawable with optional fade-in animation.

void
setMainImageAdjustViewBounds(boolean adjustViewBounds)

Enables or disables adjustment of view bounds on the main image.

void
setMainImageDimensions(int width, int height)

Sets the layout dimensions of the ImageView.

void

Sets the ScaleType of the main image.

void

Sets the title text.

Protected methods

void
void

Inherited Constants

From androidx.leanback.widget.BaseCardView
static final int

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

static final int

Indicates that a card region is always visible.

static final int

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

static final int

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.

static final int

A Card type with 2 layout areas: A main area which is always visible, and an info area that appears below the main area.

static final int

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.

static final int

A simple card type with a single layout area.

From android.view.View
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final int
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
static final String
static final String
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int
GONE = 8
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
KEEP_SCREEN_ON = 67108864
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
NO_ID = -1
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final String
VIEW_LOG_TAG = "View"
static final int
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
From android.view.ViewGroup
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

Inherited methods

From androidx.leanback.widget.BaseCardView
boolean
BaseCardView.LayoutParams
BaseCardView.LayoutParams
BaseCardView.LayoutParams
int

Returns the type of this Card.

int

This method is deprecated.

Extra view's visibility is controlled by getInfoVisibility

int

Returns the visibility of the info region of the card.

boolean

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

int[]
onCreateDrawableState(int extraSpace)
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
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

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

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
String
From android.widget.FrameLayout
boolean
FrameLayout.LayoutParams
FrameLayout.LayoutParams
CharSequence
boolean

This method is deprecated.

boolean
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
setForegroundGravity(int foregroundGravity)
void
setMeasureAllChildren(boolean measureAll)
boolean
From android.view.View
void
void
void
ViewPropertyAnimator
void
void
boolean
void
void

This method is deprecated.

void
boolean
boolean
boolean
boolean
boolean
canScrollHorizontally(int direction)
boolean
canScrollVertically(int direction)
final void
void
final void
boolean
void
void
static int
combineMeasuredStates(int curState, int newState)
int
int
int
void
WindowInsets
int
int
int
AccessibilityNodeInfo
void
void

This method is deprecated.

boolean
boolean
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
boolean
dispatchNestedPreFling(float velocityX, float velocityY)
boolean
dispatchNestedPrePerformAccessibilityAction(
    int action,
    Bundle arguments
)
boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    int[] consumed,
    int[] offsetInWindow
)
boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int[] offsetInWindow
)
boolean
void
draw(Canvas canvas)
void
drawableHotspotChanged(float x, float y)
final OnBackInvokedDispatcher
final T
<T extends View> findViewById(int id)
final T
<T extends View> findViewWithTag(Object tag)
boolean

This method is deprecated.

void
forceHasOverlappingRendering(boolean hasOverlappingRendering)
void
void
generateDisplayHash(
    String hashAlgorithm,
    Rect bounds,
    Executor executor,
    DisplayHashResultCallback callback
)
static int
View.AccessibilityDelegate
int
AccessibilityNodeProvider
CharSequence
int
int
String
String
float
Animation
Matrix
IBinder
int[]
Map<IntegerInteger>
String[]
final AutofillId
int
AutofillValue
Drawable
BlendMode
ColorStateList
PorterDuff.Mode
int
final int
float
int
float
Rect
boolean
final boolean
final ContentCaptureSession
CharSequence
final Context
ContextMenu.ContextMenuInfo
final boolean
static int
getDefaultSize(int size, int measureSpec)
Display
final int[]
Bitmap

This method is deprecated.

int

This method is deprecated.

int

This method is deprecated.

void
long
float
int
boolean
boolean
int
ArrayList<View>
getFocusables(int direction)
void
Drawable