public class

CardFragment

extends Fragment

Note: The Wearable Support Library classes under the android.support.wearable package are subject to change. For the full Android API reference, see Reference.

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

Class Overview

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
[Expand]
Inherited Constants
From interface android.content.ComponentCallbacks2
Public Constructors
CardFragment()
Public Methods
static CardFragment create(CharSequence title, CharSequence description)
Construct a new CardFragment using the default content layout.
static CardFragment create(CharSequence title, CharSequence text, int iconRes)
Construct a new CardFragment using the default content layout, including and icon.
void onActivityCreated(Bundle savedInstanceState)
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 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.
Protected Methods
View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Called to have subclasses instantiate their layout which is inserted within the card.
[Expand]
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

public static final int EXPAND_DOWN

Constant Value: 1 (0x00000001)

public static final int EXPAND_UP

Constant Value: -1 (0xffffffff)

public static final String KEY_ICON_RESOURCE

Constant Value: "CardFragment_icon"

public static final String KEY_TEXT

Constant Value: "CardFragment_text"

public static final String KEY_TITLE

Constant Value: "CardFragment_title"

Public Constructors

public CardFragment ()

Public Methods

public static CardFragment create (CharSequence title, CharSequence description)

Construct a new CardFragment using the default content layout.

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

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

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

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

public void onActivityCreated (Bundle savedInstanceState)

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

public void onDestroy ()

public void scrollToBottom ()

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

public void scrollToTop ()

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

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 a vertical gravity, either TOP or BOTTOM

public void setCardMarginBottom (int bottom)

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

Parameters
bottom the top margin

public void setCardMarginLeft (int left)

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

Parameters
left the top margin

public void setCardMarginRight (int right)

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

Parameters
right the top margin

public void setCardMarginTop (int top)

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

Parameters
top the top margin

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 the left margin
top the top margin
right the right margin
bottom the bottom margin

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

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

Parameters
left the left padding
top the top padding
right the right padding
bottom the bottom padding

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 a direction constant, either EXPAND_UP or EXPAND_DOWN

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.

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 the vertical height multiplier to set the maximum height

Protected Methods

protected 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 The LayoutInflater object that can be used to inflate any views in the fragment
container 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 If non-null, this fragment is being re-constructed from a previous saved state as given here
Returns
  • Return the View for the fragment's UI, or null