CardFragment

public class CardFragment
extends Fragment

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


This class is deprecated.
starting with Android Wear 2.0 it is no longer encouraged to use cards for apps' UI. If you are looking to implement vertical paging pattern, consider using the SnapHelper and a RecyclerView instead.

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.

Summary

Constants

int EXPAND_DOWN

int EXPAND_UP

String KEY_ICON_RESOURCE

String KEY_TEXT

String KEY_TITLE

Inherited constants

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

Constants

EXPAND_DOWN

public static final int EXPAND_DOWN

Constant Value: 1 (0x00000001)

EXPAND_UP

public static final int EXPAND_UP

Constant Value: -1 (0xffffffff)

KEY_ICON_RESOURCE

public static final String KEY_ICON_RESOURCE

Constant Value: "CardFragment_icon"

KEY_TEXT

public static final String KEY_TEXT

Constant Value: "CardFragment_text"

KEY_TITLE

public static final String KEY_TITLE

Constant Value: "CardFragment_title"

Public constructors

CardFragment

public CardFragment ()

Public methods

create

public static 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

public static 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

public Rect getContentPadding ()

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

Returns
Rect

getContentPaddingBottom

public int getContentPaddingBottom ()

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

Returns
int

getContentPaddingLeft

public int getContentPaddingLeft ()

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

Returns
int

getContentPaddingRight

public int getContentPaddingRight ()

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

Returns
int

getContentPaddingTop

public int getContentPaddingTop ()

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

Returns
int

onActivityCreated

public void onActivityCreated (Bundle savedInstanceState)

Parameters
savedInstanceState Bundle

onCreateContentView

public 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

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

Parameters
inflater LayoutInflater

container ViewGroup

savedInstanceState Bundle

Returns
View

onDestroy

public void onDestroy ()

scrollToBottom

public void scrollToBottom ()

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

scrollToTop

public void scrollToTop ()

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

setCardGravity

public 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 Gravity.TOP or Gravity.BOTTOM

setCardMarginBottom

public 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

public 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

public 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

public 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

public 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

public 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

public 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

public 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

public 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

public void setContentPaddingTop (int topPadding)

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

Parameters
topPadding int

setExpansionDirection

public 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

public 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

public 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