本项目是基于开源项目 spruce 进行ohos化的移植和开发的,可以通过项目标签以及github地址(https://github.com/willowtreeapps/spruce-android )追踪到原项目版本
方法1.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
……
}
方法2.
repositories {
maven {
url 'http://106.15.92.248:8081/repository/Releases/'
}
}
dependencies {
implementation 'com.willowtreeapps.ohos:spruce-ohos:1.0.1'
}
1.使用最多的四个主要功能类:
2.使用实例 2.1 简单线性列表子项排版动画显示
spruceAnimator = new Spruce.SpruceBuilder(listContainer)
.sortWith(new DefaultSort(100))
.excludeViews(getExcludedViews(), R_L_MODE)
.animateWith(DefaultAnimations.dynamicFadeIn(listContainer),
dynamicTranslationUpwards(listContainer))
.start();
代码说明: listContainer为需要设置动画的列表控件 DefaultSort为本库定义的子项排版的动画播放顺序 getExcludedViews为用户自定义的列表中不需要设置动画的隐藏子项序号数组列表,可参考示例如下:
private List<Integer> getExcludedViews() {
List<Integer> positions = new ArrayList<>();
if (exCludeView.isChecked()) {
positions.add(1);
positions.add(4);
positions.add(7);
}
return positions;
}
R_L_MODE为针对不同列表所需要的设置的过滤模式属性,如果该项不生效,可以尝试NORMAL_MODE 2.2 Grid列表子项排版动画显示
使用TableLayoutManager构造GridView列表显示
listContainer = (ListContainer)findComponentById(ResourceTable.Id_mainListContainer);
TableLayoutManager tableLayoutManager = new TableLayoutManager();
tableLayoutManager.setColumnCount(6);
tableLayoutManager.setRowCount(7);
listContainer.setLayoutManager(tableLayoutManager);
for (int i = 0; i < CHILD_VIEW_COUNT; i++) {
ExampleData childView = new ExampleData();
sampleData.add(childView);
}
ListViewAdapter listViewAdapter = new ListViewAdapter(sampleData);
listContainer.setItemProvider(listViewAdapter);
定义每个执行显示的动画数组
animators = new Object[]{
DefaultAnimations.dynamicTranslationUpwards(listContainer),
DefaultAnimations.dynamicFadeIn(listContainer)
};
定义不需要设置动画并隐藏的子项id值列表
private List<Integer> getExclusionViews() {
List<Integer> ids = new ArrayList<>();
if(excludeView.isChecked()){
ids.add(1);
ids.add(10);
ids.add(17);
ids.add(21);
ids.add(26);
ids.add(30);
}
return ids;
}
选择各个子项播放顺序的方式sortFunction
private void initSortFunction() {
switch (choosedSortFunction){
case 0:
sortFunction = new DefaultSort(choosedDelayTime);
break;
case 1:
sortFunction = new CorneredSort(
choosedDelayTime,isReversed.isChecked(),
switchCorner(choosedDirection));
break;
case 2:
sortFunction = new ContinuousSort(
choosedDelayTime*20,
isReversed.isChecked(),
switchPosition(choosedDirection));
break;
case 3:
sortFunction = new ContinuousWeightedSort(choosedDelayTime*20,
isReversed.isChecked(),
switchPosition(choosedDirection),
switchWeight(choosedVertical),
switchWeight(choosedHorizontal)
);
break;
case 4:
sortFunction = new InlineSort(choosedDelayTime,
isReversed.isChecked(),
switchCorner(choosedDirection));
break;
case 5:
sortFunction = new LinearSort(choosedDelayTime,
isReversed.isChecked(),
switchDirection(choosedDirection));
break;
case 6:
sortFunction = new RadialSort(choosedDelayTime,
isReversed.isChecked(),
switchPosition(choosedDirection));
break;
case 7:
sortFunction = new RandomSort(choosedDelayTime);
break;
case 8:
sortFunction = new SnakeSort(choosedDelayTime,isReversed.isChecked(),switchCorner(choosedDirection));
break;
}
}
动画设置加载
spruceAnimator = new Spruce.SpruceBuilder(listContainer).sortWith(sortFunction)
.animateWith(animators)
.excludeViews(getExclusionViews(), R_L_MODE)
.start();
2.3 SortFunction使用说明 一共支持九种子项排序播放顺序
-DefaultSort
-CorneredSort
-ContinuousSort
-ContinuousWeightedSort
-InlineSort
-LinearSort
-RadialSort
-RandomSort
-SnakeSort
每一个SortFunction都需要设置内置的延迟时间,不同的SortFunction还可以设置是否排列顺序翻转,起始位置等
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。