CardFragment

public class CardFragment
extends Fragment

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


在可展开的垂直滚动卡片中呈现内容。 默认布局包含标题,图标和文本,但可能会被重写onCreateContentView(LayoutInflater, ViewGroup, Bundle)

还提供了其他方法来调整卡的外观,包括内容是否应该剪裁或显示为可展开,以及卡的最大高度。

也可以看看:

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)

使用默认的内容布局构建新的CardFragment,包括和图标。

static CardFragment create(CharSequence title, CharSequence description)

使用默认的内容布局构建一个新的CardFragment。

Rect getContentPadding()

获取内部卡边缘和卡片内容之间的填充。

int getContentPaddingBottom()

获取内部卡的底部边缘和卡内容之间的填充。

int getContentPaddingLeft()

获取内部卡的左边缘和卡内容之间的填充。

int getContentPaddingRight()

获取内部卡右边缘和卡内容之间的填充。

int getContentPaddingTop()

获取内卡顶边和卡内容之间的填充。

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

被调用来让子类实例化插入到卡中的布局。

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

将卡片滚动位置尽可能向下设置,以便底部边缘可见。

void scrollToTop()

尽可能将卡片滚动位置设置得尽可能远,以便可看到顶部边缘。

void setCardGravity(int gravity)

将垂直重力分配给卡片,当卡片和内容短于页面时,卡片决定它应该在哪里浮动。

void setCardMarginBottom(int bottom)

设置卡影下边缘与父视图之间的附加边距。

void setCardMarginLeft(int left)

设置卡片阴影左边缘与父视图之间的附加边距。

void setCardMarginRight(int right)

设置影子右边缘与父视图之间的附加边距。

void setCardMarginTop(int top)

设置卡影上边缘与父视图之间的附加边距。

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

设置卡片阴影边缘和父视图之间的附加边距。

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

设置内部卡边缘和卡片内容之间的填充。

void setContentPaddingBottom(int bottomPadding)

设置内部卡的底部边缘和卡片内容之间的填充。

void setContentPaddingLeft(int leftPadding)

设置内部卡的左边缘和卡片内容之间的填充。

void setContentPaddingRight(int rightPadding)

设置内部卡的右边缘和卡内容之间的填充。

void setContentPaddingTop(int topPadding)

设置内卡顶边和卡内容之间的填充。

void setExpansionDirection(int direction)

调整卡片高度将扩大的方向。

void setExpansionEnabled(boolean enabled)

启用可能比卡的容器更大的支持内容。

void setExpansionFactor(float factor)

将卡所允许的最大高度设置为父高度的倍数。

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

常数值:1(0x00000001)

EXPAND_UP

int EXPAND_UP

常量值:-1(0xffffffff)

KEY_ICON_RESOURCE

String KEY_ICON_RESOURCE

常量值:“CardFragment_icon”

KEY_TEXT

String KEY_TEXT

Constant Value: "CardFragment_text"

KEY_TITLE

String KEY_TITLE

常量值:“CardFragment_title”

Public constructors

CardFragment

CardFragment ()

Public methods

create

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

使用默认的内容布局构建新的CardFragment,包括和图标。

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)

使用默认的内容布局构建一个新的CardFragment。

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

获取内部卡边缘和卡片内容之间的填充。

Returns
Rect

getContentPaddingBottom

int getContentPaddingBottom ()

获取内部卡的底部边缘和卡内容之间的填充。

Returns
int

getContentPaddingLeft

int getContentPaddingLeft ()

获取内部卡的左边缘和卡内容之间的填充。

Returns
int

getContentPaddingRight

int getContentPaddingRight ()

获取内部卡右边缘和卡内容之间的填充。

Returns
int

getContentPaddingTop

int getContentPaddingTop ()

获取内卡顶边和卡内容之间的填充。

Returns
int

onActivityCreated

void onActivityCreated (Bundle savedInstanceState)

Parameters
savedInstanceState Bundle

onCreateContentView

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

被调用来让子类实例化插入到卡中的布局。 覆盖此方法以为卡内容提供您自己的自定义布局。

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

将卡片滚动位置尽可能向下设置,以便底部边缘可见。

scrollToTop

void scrollToTop ()

尽可能将卡片滚动位置设置得尽可能远,以便可看到顶部边缘。

setCardGravity

void setCardGravity (int gravity)

将垂直重力分配给卡片,当卡片和内容短于页面时,卡片决定它应该在哪里浮动。

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

setCardMarginBottom

void setCardMarginBottom (int bottom)

设置卡影下边缘与父视图之间的附加边距。

Parameters
bottom int: the top margin

setCardMarginLeft

void setCardMarginLeft (int left)

设置卡片阴影左边缘与父视图之间的附加边距。

Parameters
left int: the top margin

setCardMarginRight

void setCardMarginRight (int right)

设置影子右边缘与父视图之间的附加边距。

Parameters
right int: the top margin

setCardMarginTop

void setCardMarginTop (int top)

设置卡影上边缘与父视图之间的附加边距。

Parameters
top int: the top margin

setCardMargins

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

设置卡片阴影边缘和父视图之间的附加边距。

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)

设置内部卡边缘和卡片内容之间的填充。

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)

设置内部卡的底部边缘和卡片内容之间的填充。

Parameters
bottomPadding int: the bottom padding

setContentPaddingLeft

void setContentPaddingLeft (int leftPadding)

设置内部卡的左边缘和卡片内容之间的填充。

Parameters
leftPadding int: the left padding

setContentPaddingRight

void setContentPaddingRight (int rightPadding)

设置内部卡的右边缘和卡内容之间的填充。

Parameters
rightPadding int: the right padding

setContentPaddingTop

void setContentPaddingTop (int topPadding)

设置内卡顶边和卡内容之间的填充。

Parameters
topPadding int

setExpansionDirection

void setExpansionDirection (int direction)

调整卡片高度将扩大的方向。 当通过滚动获得更多内容时,这也决定了哪个边缘以褪色边缘呈现。

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

setExpansionEnabled

void setExpansionEnabled (boolean enabled)

启用可能比卡的容器更大的支持内容。 当启用扩展时,内容大于卡片时,顶部或底部边缘将淡入以指示此情况。 扩展系数也必须增加以允许卡的高度增加。

Parameters
enabled boolean

setExpansionFactor

void setExpansionFactor (float factor)

将卡所允许的最大高度设置为父高度的倍数。 如果启用了扩展功能,卡片将根据需要增加高度,以适应内容。

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