鸿蒙OS开发文档 鸿蒙OS Rating

2024-02-25 开发教程 鸿蒙OS开发文档 匿名 3

Rating

java.lang.Object
|---ohos.agp.components.Component
|---|---ohos.agp.components.ProgressBar
|---|---|---ohos.agp.components.AbsSlider
|---|---|---|---ohos.agp.components.Rating

public class Rating
extends AbsSlider

提供带有评级项目的评级,例如星级或任何其他元素。

此类提供带有评级项目(如星号(或元素))的评级,以表示评级级别。

Since:

3

嵌套类摘要

修饰符和类型描述
static interfaceRating.RatingChangedListener回调以处理评级的更改事件。
从类 ohos.agp.components.AbsSlider 继承的嵌套类/接口
AbsSlider.Formatter
从类 ohos.agp.components.Component 继承的嵌套类/接口
Component.BindStateChangedListener, Component.CanAcceptScrollListener, Component.ClickedListener, Component.ComponentStateChangedListener, Component.ContourRefreshedListener, Component.DefSpeechEventListener, Component.DoubleClickedListener, Component.DragFeedbackProvider, Component.DraggedListener, Component.DrawTask, Component.EditEventListener, Component.EstimateSizeListener, Component.EstimateSpec, Component.FadeEffectEnum, Component.FocusChangedListener, Component.ForwardHoverListener, Component.ForwardTouchListener, Component.GestureType, Component.HoverEventListener, Component.KeyEventListener, Component.LayoutDirection, Component.LayoutRefreshedListener, Component.LongClickedListener, Component.MeasureSpec, Component.MouseEventListener, Component.MousePointerStyleListener, Component.OnDragListener, Component.RotationEventListener, Component.ScaledListener, Component.ScrolledListener, Component.ShadowDevice, Component.ShadowMode, Component.ShadowSize, Component.SpeechEventListener, Component.TouchEventListener, Component.UnconsumedKeyEventListener, Component.VoiceEvent
从类 ohos.agp.components.ProgressBar 继承的嵌套类/接口
ProgressBar.BarObserver

字段摘要

从类 ohos.agp.components.Component 继承的字段
ACCESSIBILITY_ADAPTABLE, ACCESSIBILITY_DISABLE, ACCESSIBILITY_ENABLE, AXIS_X, AXIS_Y, CONTOUR_BACKGROUND, CONTOUR_BORDER, CONTOUR_PADDING_BORDER, DEFAULT_SCALE, DRAG_DOWN, DRAG_HORIZONTAL, DRAG_HORIZONTAL_VERTICAL, DRAG_LEFT, DRAG_RIGHT, DRAG_UP, DRAG_VERTICAL, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED_CLEAR, EVENT_TYPE_COMPONENT_CLICKED, EVENT_TYPE_COMPONENT_FOCUSED, EVENT_TYPE_COMPONENT_LONG_CLICKED, EVENT_TYPE_COMPONENT_SCROLLED, EVENT_TYPE_COMPONENT_SELECTED, EVENT_TYPE_COMPONENT_TEXT_UPDATE, EVENT_TYPE_NOTICE, EVENT_TYPE_NOTIFICATION_STATE_UPDATE, EVENT_TYPE_TOAST_SHOW, EVENT_TYPE_WINDOW_STATE_UPDATE, FOCUS_ADAPTABLE, FOCUS_DISABLE, FOCUS_ENABLE, FOCUS_NEXT, FOCUS_PREVIOUS, FOCUS_SIDE_BOTTOM, FOCUS_SIDE_LEFT, FOCUS_SIDE_RIGHT, FOCUS_SIDE_TOP, HIDE, HORIZONTAL, ID_DEFAULT, INHERITED_MODE, INVISIBLE, mBackgroundElement, mCanvasForTaskOverContent, mCanvasForTaskUnderContent, mComponentParent, mContext, mDrawTaskOverContent, mDrawTaskUnderContent, mEstimateSizeListener, mForegroundElement, mForwardHoverListener, mHoverEventListener, mKeyEventListener, mMouseEventListener, mPosition, mRotationEventListener, mShadowElement, mUnconsumedKeyEventListener, OVAL_MODE, OVAL_SCROLL_BAR_MODE, POSITION_X_INDEX, POSITION_Y_INDEX, RECT_MODE, RECT_SCROLL_BAR_MODE, SCROLL_AUTO_STAGE, SCROLL_IDLE_STAGE, SCROLL_NORMAL_STAGE, UNSPECIFIED_SCROLL_BAR_MODE, VERTICAL, VISIBLE

构造函数摘要

构造函数描述
Rating(Context context)用于使用默认属性集和样式创建 Rating 实例的默认构造函数。
Rating(Context context, AttrSet attrSet)用于在解析 XML 文件后使用指定的属性集和默认样式创建 Rating 实例的构造函数。
Rating(Context context, AttrSet attrSet, String styleName)用于在解析 XML 文件后使用指定的属性集和指定样式创建 Rating 实例的构造函数。

方法总结

修饰符和类型方法描述
ElementgetFilledElement()从评分项中获取填充元素。
floatgetGrainSize()获取评级项目的步长(粒度)。
ElementgetHalfFilledElement()从评分项中获取半填充元素。
intgetRatingItems()获取当前评分项的数量。
floatgetScore()获取当前评分。
ElementgetThumbElement()获取当前元素拇指。
ElementgetUnfilledElement()从评分项中获取未填充的元素。
booleanisOperable()检查评级是否不可操作。
voidsetFilledElement(Element element)将指定的 Element 对象设置为评级项目的填充元素。
voidsetGrainSize(float size)设置评级项目的步长。
voidsetHalfFilledElement(Element element)将指定的 Element 对象设置为评级项目的半填充元素。
voidsetIsOperable(boolean isOperable)设置评级是否不可操作。
voidsetRatingChangedListener(Rating.RatingChangedListener listener)设置更改侦听器以处理评级的更改事件。
voidsetRatingItems(int numberItems)设置由星号或其他符号表示的评级项目的数量以表示评级级别。
voidsetScore(float score)设置评分。
voidsetThumbElement(Element element)设置元素拇指。
voidsetUnfilledElement(Element element)将指定的 Element 对象设置为评级项目的未填充元素。
从类 ohos.agp.components.AbsSlider 继承的方法
getFormatter, setFormatter
从类 ohos.agp.components.Component 继承的方法
addDrawTask, addDrawTask, addScrolledListener, announceAccessibility, arrange, bindCornerMark, callOnClick, canScroll, clearFocus, createAnimatorProperty, disableFadeEffect, dispatchRestoreState, dispatchSaveState, draw, enableCornerMark, enableFadeEffect, enableSaveState, enableScrollBar, estimateSize, executeDoubleClick, executeLongClick, findComponentById, findComponentHolderById, findFocus, findNextFocusableComponent, findRequestNextFocus, getAccessibility, getAccessibilityDescription, getAlpha, getAltitude, getBackgroundElement, getBaseLine, getBottom, getBoundaryFadeEffectBottomRate, getBoundaryFadeEffectLeftRate, getBoundaryFadeEffectRightRate, getBoundaryFadeEffectTopRate, getCenterZoomFactor, getCentralScrollMode, getClickedListener, getClipEnabled, getComponentDescription, getComponentMinSize, getComponentParent, getComponentPosition, getComponentSize, getComponentStateChangedListener, getComponentTreeObserver, getContentEnable, getContentPosition, getContentPositionX, getContentPositionY, getContext, getContour, getContourRefreshedListener, getCornerMark, getDragAcceptAngle, getDraggedListener, getEditEventListener, getEstimatedHeight, getEstimatedWidth, getFadeEffectBoundaryWidth, getFadeEffectColor, getFocusable, getFocusBorderEnable, getFocusBorderPadding, getFocusBorderRadius, getFocusBorderWidth, getForegroundElement, getForegroundGravity, getForwardHoverListener, getForwardTouchListener, getGesturePriority, getHeight, getHorizontalPadding, getHorizontalPosition, getHoverEventListener, getId, getKeyEventListener, getLayoutConfig, getLayoutDirection, getLayoutDirectionResolved, getLayoutRefreshedListener, getLeft, getLocationOnScreen, getMarginBottom, getMarginLeft, getMarginRight, getMargins, getMarginsLeftAndRight, getMarginsTopAndBottom, getMarginTop, getMatrix, getMinHeight, getMinWidth, getMode, getModeResolved, getMouseEventListener, getMousePointerStyleListener, getName, getPadding, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getPivot, getPivotX, getPivotY, getResourceManager, getRight, getRotation, getRotationEventListener, getRotationSensitivity, getScale, getScaledListener, getScaleX, getScaleY, getScrollbarBackgroundColor, getScrollbarColor, getScrollbarFadingDelay, getScrollbarFadingDuration, getScrollBarMode, getScrollbarRadius, getScrollbarRoundRect, getScrollbarStartAngle, getScrollbarSweepAngle, getScrollbarThickness, getScrollState, getScrollValue, getSelfVisibleRect, getShadowColor, getSpeechEventListener, getTag, getTop, getTouchEventListener, getTransitionSymbol, getTranslation, getTranslationX, getTranslationY, getTranslationZ, getUserNextFocus, getVerticalPadding, getVerticalPosition, getVisibility, getVisibleRectOnScreen, getWidth, getWindowVisibleRect, hasFocus, hasFocusedEffect, hasOverlaps, hideFocusBorder, informConfigurationChanged, invalidate, isBoundaryFadeEffectEnable, isBoundToWindow, isClickable, isClipToContourEnabled, isComponentDisplayed, isEnabled, isFadeEffected, isFocusable, isFocused, isIdentityMatrix, isLongClickOn, isPressed, isRtl, isSaveStateEnabled, isScrollbarFadingOn, isScrollBarOn, isScrollbarOverlapEnabled, isSelected, isSoundEnable, isTouchFocusable, isVibrationEffectEnabled, notifyAccessibility, onAttributeConfigChanged, onDrag, onRestoreState, onRtlChanged, onSaveState, performScale, playSound, postLayout, refreshContour, release, removeBindStateChangedListener, removeScrolledListener, requestFocus, requestForceForwardTouchEvent, restoreComponentTreeState, saveComponentTreeState, scrollBy, scrollTo, setAccessibility, setAccessibilityDescription, setAlpha, setAltitude, setBackground, setBindStateChangedListener, setBottom, setBoundaryFadeEffectEnable, setCanAcceptScrollListener, setCenterZoomFactor, setCentralScrollMode, setClickable, setClickedListener, setClipEnabled, setClipToContourEnabled, setComponentDescription, setComponentMinSize, setComponentPosition, setComponentPosition, setComponentSize, setComponentStateChangedListener, setContentEnable, setContentPosition, setContentPositionX, setContentPositionY, setContour, setContourRefreshedListener, setDoubleClickedListener, setDragAcceptAngle, setDraggedListener, setEditEventListener, setEnabled, setEstimatedSize, setEstimateSizeListener, setFadeEffectBoundaryWidth, setFadeEffectColor, setFocusable, setFocusBorderEnable, setFocusBorderPadding, setFocusBorderRadius, setFocusBorderRadius, setFocusBorderWidth, setFocusChangedListener, setFocusedEffect, setForeground, setForegroundGravity, setForwardHoverListener, setForwardTouchListener, setGesturePriority, setHeight, setHorizontalPadding, setHorizontalPosition, setHoverEventListener, setId, setKeyEventListener, setLayoutConfig, setLayoutDirection, setLayoutRefreshedListener, setLeft, setLongClickable, setLongClickedListener, setMarginBottom, setMarginLeft, setMarginRight, setMarginsLeftAndRight, setMarginsTopAndBottom, setMarginTop, setMinHeight, setMinWidth, setMode, setMouseEventListener, setMousePointerStyleListener, setName, setOnDragListener, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRelative, setPaddingRight, setPaddingTop, setPivot, setPivot, setPivotX, setPivotY, setPosition, setPositionX, setPositionY, setPressState, setRight, setRotation, setRotationEventListener, setRotationSensitivity, setScale, setScaledListener, setScaleX, setScaleY, setScrollbarBackgroundColor, setScrollbarColor, setScrollbarFadingDelay, setScrollbarFadingDuration, setScrollbarFadingEnabled, setScrollBarMode, setScrollbarOverlapEnabled, setScrollbarRadius, setScrollbarRoundRect, setScrollbarStartAngle, setScrollbarSweepAngle, setScrollbarThickness, setScrolledListener, setSelected, setShadowColor, setShadowStyle, setSoundEnable, setSpeechEventListener, setTag, setTop, setTouchEventListener, setTouchFocusable, setTransitionSymbol, setTranslation, setTranslationX, setTranslationY, setTranslationZ, setUnconsumedKeyEventListener, setUserNextFocus, setVerticalPadding, setVerticalPosition, setVibrationEffectEnabled, setVisibility, setWidth, showFocusBorder, simulateClick, simulateDrag, startDragAndDrop, subscribeVoiceEvents, unsubscribeVoiceEvents
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从类 ohos.agp.components.ProgressBar 继承的方法
addBarObserver, enableDividerLines, getBackgroundInstructElement, getDividerLineColor, getDividerLinesNumber, getDividerLineThickness, getInfiniteModeElement, getMax, getMaxHeight, getMaxWidth, getMin, getOrientation, getProgress, getProgressColor, getProgressColors, getProgressElement, getProgressHintText, getProgressHintTextAlignment, getProgressHintTextColor, getProgressHintTextSize, getProgressWidth, getStep, getViceProgressElement, getViceProgressValue, isDividerLinesEnabled, isIndeterminate, isInfiniteMode, removeBarObserver, setDividerLineColor, setDividerLinesNumber, setDividerLineThickness, setIndeterminate, setInfiniteModeElement, setMaxHeight, setMaxValue, setMaxWidth, setMinValue, setOrientation, setProgressBackgroundElement, setProgressColor, setProgressColors, setProgressElement, setProgressHintText, setProgressHintTextAlignment, setProgressHintTextColor, setProgressHintTextSize, setProgressValue, setProgressWidth, setStep, setViceProgress, setViceProgressElement

构造函数详细信息

Rating

public Rating(Context context)

用于使用默认属性集和样式创建 Rating 实例的默认构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。

Since:

4

Rating

public Rating(Context context, AttrSet attrSet)

用于在解析 XML 文件后使用指定的属性集和默认样式创建 Rating 实例的构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。
attrSet指示要使用的属性集。

Since:

4

Rating

public Rating(Context context, AttrSet attrSet, String styleName)

用于在解析 XML 文件后使用指定的属性集和指定样式创建 Rating 实例的构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。
attrSet指示要使用的属性集。
styleName指示要使用的样式名称。

Since:

4

方法详情

getGrainSize

public float getGrainSize()

获取评级项目的步长(粒度)。

返回:

返回评级步长。

Since:

4

setGrainSize

public void setGrainSize(float size)

设置评级项目的步长。

参数:

参数名称参数描述
size指示要设置的步长。

Throws:

Throw名称Throw描述
IllegalArgumentException如果 size 值小于或等于 0 或大于评级项目的数量,则引发异常,请参阅 Rating#getRatingItems()

Since:

4

setScore

public void setScore(float score)

设置评分。

参数:

参数名称参数描述
score表示要设置的分数,它是一个浮点值。

Throws:

Throw名称Throw描述
IllegalArgumentException如果 score 值小于 0,则抛出异常

Since:

4

getScore

public float getScore()

获取当前评分。

返回:

返回当前评分。

Since:

4

setIsOperable

public void setIsOperable(boolean isOperable)

设置评级是否不可操作。

参数:

参数名称参数描述
isOperable指定评级是否不可操作。 值 true 表示评级不可操作,false 表示相反。

Since:

4

isOperable

public boolean isOperable()

检查评级是否不可操作。

返回:

如果评级不可操作,则返回真; 否则返回 false。

Since:

4

setRatingItems

public void setRatingItems(int numberItems)

设置由星号或其他符号表示的评级项目的数量以表示评级级别。

参数:

参数名称参数描述
numberItems表示评级项目的数量。

Throws:

Throw名称Throw描述
IllegalArgumentException如果值小于 0 或大于评级项目的上限 RATING_MAX_ITEMS,则引发异常

Since:

4

getRatingItems

public int getRatingItems()

获取当前评分项的数量。

通常,较高的评级级别由较大数量的星号(或其他符号)表示。

返回:

返回评级项目的数量。

Since:

4

setRatingChangedListener

public void setRatingChangedListener(Rating.RatingChangedListener listener)

设置更改侦听器以处理评级的更改事件。

参数:

参数名称参数描述
listener指示应用程序传递的更改侦听器,用于处理评分的更改事件。

Since:

4

setFilledElement

public void setFilledElement(Element element)

将指定的 Element 对象设置为评级项目的填充元素。

参数:

参数名称参数描述
element指示要设置的 Element 对象。

Since:

4

getFilledElement

public Element getFilledElement()

从评分项中获取填充元素。

返回:

返回元素对象。

Since:

4

setUnfilledElement

public void setUnfilledElement(Element element)

将指定的 Element 对象设置为评级项目的未填充元素。

参数:

参数名称参数描述
element指示要设置的 Element 对象。

Since:

4

getHalfFilledElement

public Element getHalfFilledElement()

从评分项中获取半填充元素。

返回:

返回元素对象。

Since:

4

setHalfFilledElement

public void setHalfFilledElement(Element element)

将指定的 Element 对象设置为评级项目的半填充元素。

参数:

Parameter NameParameter Description
elementIndicates the Element object to set.

Since:

4

getUnfilledElement

public Element getUnfilledElement()

从评分项中获取未填充的元素。

返回:

返回元素对象。

Since:

4

getThumbElement

public Element getThumbElement()

从类复制的描述:AbsSlider

获取当前元素拇指。

覆盖:

类 AbsSlider 中的 getThumbElement

返回:

指示当前元素缩略图。

setThumbElement

public void setThumbElement(Element element)

从类复制的描述:AbsSlider

设置元素拇指。

覆盖:

类 AbsSlider 中的 setThumbElement

参数:

参数名称参数描述
element指示元素拇指。