CardFragment

public class CardFragment
extends Fragment

java.lang.Object
   ↳ android.app.Fragment
     ↳ android.support.wearable.view.CardFragment


Presents content within an expandable, vertically scrollable card. The default layout contains a title, icon and text, but may be replaced by overriding onCreateContentView(LayoutInflater, ViewGroup, Bundle).

Additional methods are supplied for adjusting the appearance of the card, including whether content should clip or appear as expandable, and the maximum height of the card.

See also:

Summary

Constants

int EXPAND_DOWN

int EXPAND_UP

String KEY_ICON_RESOURCE

String KEY_TEXT

String KEY_TITLE

Inherited constants

From interface android.content.ComponentCallbacks2

Public constructors

CardFragment()

Public methods

static CardFragment create(CharSequence title, CharSequence text, int iconRes)

Construct a new CardFragment using the default content layout, including and icon.

static CardFragment create(CharSequence title, CharSequence description)

Construct a new CardFragment using the default content layout.

Rect getContentPadding()

Gets the padding between the inside card edge and the card content.

int getContentPaddingBottom()

Gets the padding between the inside card's bottom edge and the card content.

int getContentPaddingLeft()

Gets the padding between the inside card's left edge and the card content.

int getContentPaddingRight()

Gets the padding between the inside card's right edge and the card content.

int getContentPaddingTop()

Gets the padding between the inside card's top edge and the card content.

void onActivityCreated(Bundle savedInstanceState)
View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Called to have subclasses instantiate their layout which is inserted within the card.

final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
void onDestroy()
void scrollToBottom()

Sets the card scroll position as far down as possible so the bottom edge is visible.

void scrollToTop()

Sets the card scroll position as far up as possible so the top edge is visible.

void setCardGravity(int gravity)

Assigns vertical gravity to the card, which determines where it should float when the card and it's content are shorter than the page.

void setCardMarginBottom(int bottom)

Sets the additional margin between the bottom edge of the card shadow, and the parent view.

void setCardMarginLeft(int left)

Sets the additional margin between the left edge of the card shadow, and the parent view.

void setCardMarginRight(int right)

Sets the additional margin between the right edge of the card shadow, and the parent view.

void setCardMarginTop(int top)

Sets the additional margin between the top edge of the card shadow, and the parent view.

void setCardMargins(int left, int top, int right, int bottom)

Sets the additional margin between the card shadow edge and the parent view.

void setContentPadding(int left, int top, int right, int bottom)

Sets padding between the inside card edge and the card content.

void setContentPaddingBottom(int bottomPadding)

Sets the padding between the inside card's bottom edge and the card content.

void setContentPaddingLeft(int leftPadding)

Sets the padding between the inside card's left edge and the card content.

void setContentPaddingRight(int rightPadding)

Sets the padding between the inside card's right edge and the card content.

void setContentPaddingTop(int topPadding)

Sets the padding between the inside card's top edge and the card content.

void setExpansionDirection(int direction)

Adjusts which direction the card height will expand.

void setExpansionEnabled(boolean enabled)

Enables support contents which maybe be larger than the card's container.

void setExpansionFactor(float factor)

Sets the allowed maximum height of the card as a multiple of the parent height.

Inherited methods

From class android.app.Fragment
From class java.lang.Object
From interface android.content.ComponentCallbacks2
From interface android.view.View.OnCreateContextMenuListener
From interface android.content.ComponentCallbacks

Constants

EXPAND_DOWN

int EXPAND_DOWN

Constant Value: 1 (0x00000001)

EXPAND_UP

int EXPAND_UP

Constant Value: -1 (0xffffffff)

KEY_ICON_RESOURCE

String KEY_ICON_RESOURCE

Constant Value: "CardFragment_icon"

KEY_TEXT

String KEY_TEXT

Constant Value: "CardFragment_text"

KEY_TITLE

String KEY_TITLE

Constant Value: "CardFragment_title"

Public constructors

CardFragment

CardFragment ()

Public methods

create

CardFragment create (CharSequence title,
                CharSequence text,
                int iconRes)

Construct a new CardFragment using the default content layout, including and icon.

Parameters
title CharSequence: the card title displayed on the first line
text CharSequence: the card text displayed below the title
iconRes int: a resourceId for an icon to be displayed next to the title
Returns
CardFragment a new CardFragment

create

CardFragment create (CharSequence title,
                CharSequence description)

Construct a new CardFragment using the default content layout.

Parameters
title CharSequence: the card title displayed on the first line
description CharSequence: the card text displayed below the title
Returns
CardFragment a new CardFragment

getContentPadding

Rect getContentPadding ()

Gets the padding between the inside card edge and the card content.

Returns
Rect

getContentPaddingBottom

int getContentPaddingBottom ()

Gets the padding between the inside card's bottom edge and the card content.

Returns
int

getContentPaddingLeft

int getContentPaddingLeft ()

Gets the padding between the inside card's left edge and the card content.

Returns
int

getContentPaddingRight

int getContentPaddingRight ()

Gets the padding between the inside card's right edge and the card content.

Returns
int

getContentPaddingTop

int getContentPaddingTop ()

Gets the padding between the inside card's top edge and the card content.

Returns
int

onActivityCreated

void onActivityCreated (Bundle savedInstanceState)

Parameters
savedInstanceState Bundle

onCreateContentView

View onCreateContentView (LayoutInflater inflater,
                ViewGroup container,
                Bundle savedInstanceState)

Called to have subclasses instantiate their layout which is inserted within the card. Override this method to supply your own custom layout for the card content.

Parameters
inflater LayoutInflater: The LayoutInflater object that can be used to inflate any views in the fragment
container ViewGroup: If non-null, this is the parent view that the fragment's UI should be attached to. The fragment should not add the view itself, but this can be used to generate the LayoutParams of the view
savedInstanceState Bundle: If non-null, this fragment is being re-constructed from a previous saved state as given here
Returns
View Return the View for the fragment's UI, or null

onCreateView

View onCreateView (LayoutInflater inflater,
                ViewGroup container,
                Bundle savedInstanceState)

Parameters
inflater LayoutInflater
container ViewGroup
savedInstanceState Bundle
Returns
View

onDestroy

void onDestroy ()

scrollToBottom

void scrollToBottom ()

Sets the card scroll position as far down as possible so the bottom edge is visible.

scrollToTop

void scrollToTop ()

Sets the card scroll position as far up as possible so the top edge is visible.

setCardGravity

void setCardGravity (int gravity)

Assigns vertical gravity to the card, which determines where it should float when the card and it's content are shorter than the page.

Parameters
gravity int: a vertical gravity, either TOP or BOTTOM

setCardMarginBottom

void setCardMarginBottom (int bottom)

Sets the additional margin between the bottom edge of the card shadow, and the parent view.

Parameters
bottom int: the top margin

setCardMarginLeft

void setCardMarginLeft (int left)

Sets the additional margin between the left edge of the card shadow, and the parent view.

Parameters
left int: the top margin

setCardMarginRight

void setCardMarginRight (int right)

Sets the additional margin between the right edge of the card shadow, and the parent view.

Parameters
right int: the top margin

setCardMarginTop

void setCardMarginTop (int top)

Sets the additional margin between the top edge of the card shadow, and the parent view.

Parameters
top int: the top margin

setCardMargins

void setCardMargins (int left,
                int top,
                int right,
                int bottom)

Sets the additional margin between the card shadow edge and the parent view.

Parameters
left int: the left margin
top int: the top margin
right int: the right margin
bottom int: the bottom margin

setContentPadding

void setContentPadding (int left,
                int top,
                int right,
                int bottom)

Sets padding between the inside card edge and the card content.

Parameters
left int: the left padding
top int: the top padding
right int: the right padding
bottom int: the bottom padding

setContentPaddingBottom

void setContentPaddingBottom (int bottomPadding)

Sets the padding between the inside card's bottom edge and the card content.

Parameters
bottomPadding int: the bottom padding

setContentPaddingLeft

void setContentPaddingLeft (int leftPadding)

Sets the padding between the inside card's left edge and the card content.

Parameters
leftPadding int: the left padding

setContentPaddingRight

void setContentPaddingRight (int rightPadding)

Sets the padding between the inside card's right edge and the card content.

Parameters
rightPadding int: the right padding

setContentPaddingTop

void setContentPaddingTop (int topPadding)

Sets the padding between the inside card's top edge and the card content.

Parameters
topPadding int

setExpansionDirection

void setExpansionDirection (int direction)

Adjusts which direction the card height will expand. This also determines which edge is rendered with a faded edge when more content is available by scrolling.

Parameters
direction int: a direction constant, either EXPAND_UP or EXPAND_DOWN

setExpansionEnabled

void setExpansionEnabled (boolean enabled)

Enables support contents which maybe be larger than the card's container. When expansion is enabled, and the contents are larger than the card, the top or bottom edge will fade to indicate this. The expansion factor must also be increased to allow the card to increase in height.

Parameters
enabled boolean

setExpansionFactor

void setExpansionFactor (float factor)

Sets the allowed maximum height of the card as a multiple of the parent height. If expansion is enabled, The card will increase in height up to this amount as needed to accommodate content.

Parameters
factor float: the vertical height multiplier to set the maximum height