ImageCardView

open class ImageCardView : BaseCardView
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.FrameLayout
   ↳ androidx.leanback.widget.BaseCardView
   ↳ androidx.leanback.widget.ImageCardView

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 R.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(Context) 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> 
androidx.leanback.R.attr#imageCardViewStyle androidx.leanback.R.attr#lbImageCardViewType androidx.leanback.R.attr#imageCardViewTitleStyle androidx.leanback.R.attr#imageCardViewContentStyle androidx.leanback.R.attr#imageCardViewBadgeStyle androidx.leanback.R.attr#imageCardViewImageStyle androidx.leanback.R.attr#imageCardViewInfoAreaStyle

Summary

Constants
static Int

static Int

static Int

static Int

static Int

Inherited constants
Public constructors
<init>(context: Context!, themeResId: Int)

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);

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

<init>(context: Context!)

<init>(context: Context!, attrs: AttributeSet!)

Public methods
open CharSequence!

Returns the content text.

open Unit

Sets the content text.

open Unit

Sets the title text.

ImageView!

Returns the main image view.

open Drawable!

Returns the ImageView drawable.

open Unit
setMainImage(drawable: Drawable!)

Sets the image drawable with fade-in animation.

open Unit
setMainImage(drawable: Drawable!, fade: Boolean)

Sets the image drawable with optional fade-in animation.

open Unit
setMainImageDimensions(width: Int, height: Int)

Sets the layout dimensions of the ImageView.

open Boolean

open Unit

Sets the ScaleType of the main image.

open Unit

Sets the info area background drawable.

open Unit
setBadgeImage(drawable: Drawable!)

Sets the badge image drawable.

open Unit

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

open Drawable!

Returns the info area background drawable.

open CharSequence!

Returns the title text.

open Drawable!

Returns the badge image drawable.

open Unit

Sets the info area background color.

Protected methods
open Unit

open Unit

Inherited functions

Constants

CARD_TYPE_FLAG_IMAGE_ONLY

static val CARD_TYPE_FLAG_IMAGE_ONLY: Int
Value: 0

CARD_TYPE_FLAG_TITLE

static val CARD_TYPE_FLAG_TITLE: Int
Value: 1

CARD_TYPE_FLAG_CONTENT

static val CARD_TYPE_FLAG_CONTENT: Int
Value: 2

CARD_TYPE_FLAG_ICON_RIGHT

static val CARD_TYPE_FLAG_ICON_RIGHT: Int
Value: 4

CARD_TYPE_FLAG_ICON_LEFT

static val CARD_TYPE_FLAG_ICON_LEFT: Int
Value: 8

Public constructors

<init>

ImageCardView(context: Context!, themeResId: Int)

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);

Create an ImageCardView using a given theme for customization.

Parameters
context Context!: The Context the view is running in, through which it can access the current theme, resources, etc.
themeResId Context!: The resourceId of the theme you want to apply to the ImageCardView. The theme includes attributes "imageCardViewStyle", "imageCardViewTitleStyle", "imageCardViewContentStyle" etc. to customize individual part of ImageCardView.

<init>

ImageCardView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

<init>

ImageCardView(context: Context!)

<init>

ImageCardView(context: Context!, attrs: AttributeSet!)

Public methods

getContentText

open fun getContentText(): CharSequence!

Returns the content text.

setContentText

open fun setContentText(text: CharSequence!): Unit

Sets the content text.

setTitleText

open fun setTitleText(text: CharSequence!): Unit

Sets the title text.

getMainImageView

fun getMainImageView(): ImageView!

Returns the main image view.

getMainImage

open fun getMainImage(): Drawable!

Returns the ImageView drawable.

setMainImage

open fun setMainImage(drawable: Drawable!): Unit

Sets the image drawable with fade-in animation.

setMainImage

open fun setMainImage(drawable: Drawable!, fade: Boolean): Unit

Sets the image drawable with optional fade-in animation.

setMainImageDimensions

open fun setMainImageDimensions(width: Int, height: Int): Unit

Sets the layout dimensions of the ImageView.

hasOverlappingRendering

open fun hasOverlappingRendering(): Boolean

setMainImageScaleType

open fun setMainImageScaleType(scaleType: ScaleType!): Unit

Sets the ScaleType of the main image.

setInfoAreaBackground

open fun setInfoAreaBackground(drawable: Drawable!): Unit

Sets the info area background drawable.

setBadgeImage

open fun setBadgeImage(drawable: Drawable!): Unit

Sets the badge image drawable.

setMainImageAdjustViewBounds

open fun setMainImageAdjustViewBounds(adjustViewBounds: Boolean): Unit

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

getInfoAreaBackground

open fun getInfoAreaBackground(): Drawable!

Returns the info area background drawable.

getTitleText

open fun getTitleText(): CharSequence!

Returns the title text.

getBadgeImage

open fun getBadgeImage(): Drawable!

Returns the badge image drawable.

setInfoAreaBackgroundColor

open fun setInfoAreaBackgroundColor(color: Int): Unit

Sets the info area background color.

Protected methods

onAttachedToWindow

protected open fun onAttachedToWindow(): Unit

onDetachedFromWindow

protected open fun onDetachedFromWindow(): Unit