Harmony OS — PageSliderIndicator滑动页面指示器
2023-09-14 09:13:54 时间
1、PageSliderIndicator 是什么?
简单:滑动页面指示器
官方:PageSliderIndicator,需配合PageSlider使用,指示在PageSlider中展示哪个界面。
2、简单使用
🔺这里是在之前的 PageSlider组件上新增代码进行实现,学习或源码可参考:
Harmony OS — PageSlider滑动页面
<PageSliderIndicator
ohos:id="$+id:indicator"
ohos:height="match_content"
ohos:width="match_content"
ohos:padding="8vp"
ohos:layout_alignment="horizontal_center"
ohos:top_margin="16vp"
ohos:background_element="#55FFC0CB"/>
PageSliderIndicator indicator = (PageSliderIndicator)findComponentById(ResourceTable.Id_indicator);
ShapeElement normalElement = new ShapeElement();
normalElement.setRgbColor(RgbColor.fromArgbInt(0xADD8E6));
normalElement.setAlpha(168);
normalElement.setShape(ShapeElement.OVAL);
normalElement.setBounds(0, 0, 32, 32);
ShapeElement selectedElement = new ShapeElement();
selectedElement.setRgbColor(RgbColor.fromArgbInt(0x00BFFF));
selectedElement.setAlpha(168);
selectedElement.setShape(ShapeElement.OVAL);
selectedElement.setBounds(0, 0, 48, 48);
indicator.setItemElement(normalElement, selectedElement);
indicator.setItemOffset(60);
indicator.setPageSlider(pageSlider);
3、常用方法
(1)关联PageSlider
indicator.setPageSlider(pageSlider);
(2)响应页面更改事件
indicator.addOnSelectionChangedListener(new PageSlider.PageChangedListener() {
@Override
public void onPageSliding(int i, float v, int i1) {
}
@Override
public void onPageSlideStateChanged(int i) {
}
@Override
public void onPageChosen(int i) {
}
});
(3)设置所选指导航点的位置
indicator.setSelected(2);
此方法也会改变关联的PageSlider对象中的页面。
(4)自定义导航点的背景
除了上述使用Java创建背景外,也可以使用XML方式创建。
- a.在graphic文件夹下创建selected_page_bg_element.xml。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="rectangle">
<corners
ohos:radius="16px"/>
<bounds
ohos:top="0"
ohos:left="0"
ohos:right="64px"
ohos:bottom="32px"/>
<solid
ohos:color="#00BFFF"/>
</shape>
- b.在graphic文件夹下创建unselected_page_bg_element.xml。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="oval">
<bounds
ohos:top="0"
ohos:left="0"
ohos:right="32px"
ohos:bottom="32px"/>
<solid
ohos:color="#ADD8E6"/>
</shape>
- c.在Java代码中调用,设置导航点背景。
ShapeElement normalElement = new ShapeElement(this, ResourceTable.Graphic_unselected_page_bg_element);
ShapeElement selectedElement = new ShapeElement(this, ResourceTable.Graphic_selected_page_bg_element);
indicator.setItemElement(normalElement, selectedElement);
(5)设置导航点之间的偏移量
indicator.setItemOffset(60);
4、更多
相关文章
- 【【henuacm2016级暑期训练】动态规划专题 M】Little Pony and Harmony Chest
- 【53.57%】【codeforces 610C】Harmony Analysis
- Open Harmony移植:build lite配置目录全梳理
- Open Harmony移植:build lite编译构建过程
- cellchat_xfy_sepsis 标准流程harmony standard pipelines
- harmony与sct与harmony seurat中的 SCT连用
- harmony去批次整合模态数据seurat findintegrationanchors transferdata reference-based label transfer注释超大数据集整合
- 标准流程surat subset_data allmerge Seurat流程 碎石图ElbowPlot harmony
- open harmony
- Harmony OS — Text文本框
- Harmony OS — TextField输入框
- Harmony OS — Image图片
- Harmony OS — TabList和Tab分页栏
- Harmony OS — Picker滑动选择器
- Harmony OS — DatePicker日期选择器
- Harmony OS — TimePicker时间选择器
- Harmony OS — Switch开关状态
- Harmony OS — RadioButton & RadioContainer单选按钮&单选按钮组
- Harmony OS — Checkbox多选框
- Harmony OS — ProgressBar垂直、水平进度条
- Harmony OS — RoundProgressBar圆形进度条
- Harmony OS — ToastDialog提示对话框
- Harmony OS — ScrollView滑动视图
- Harmony OS — ListContainer列表
- Harmony OS — PageSlider滑动页面
- harmony去批次整合模态数据seurat findintegrationanchors transferdata reference-based label transfer注释超大数据集整合
- 标准流程surat subset_data allmerge Seurat流程 碎石图ElbowPlot harmony