代码拉取完成,页面将自动刷新
本项目是基于开源项目 ItemAnimators 进行ohos化的移植和开发的,可以通过项目标签以及github地址(https://github.com/mikepenz/ItemAnimators )追踪到原项目版本
方法(一)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
……
}
方法(二)
1.在工程的build.gradle的allprojects中,添加HAR所在的Maven仓地址
repositories {
maven {
url 'http://106.15.92.248:8081/repository/Releases/'
}
}
2.在应用模块的build.gradle的dependencies闭包中,添加如下代码:
dependencies {
implementation 'com.mikepenz.itemanimators.ohos:itemAnimators:1.0.0'
}
(1) 设置布局 ability_main.xml
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical">
<Component
ohos:height="40vp"
ohos:background_element="#66EEFF41"
ohos:width="match_parent"/>
<DirectionalLayout
ohos:height="55vp"
ohos:width="match_parent"
ohos:alignment="vertical_center"
ohos:background_element="#eeff41"
ohos:orientation="horizontal">
<Text
ohos:id="$+id:typeText"
ohos:height="match_content"
ohos:width="150vp"
ohos:bubble_right_height="10vp"
ohos:bubble_right_width="10vp"
ohos:element_right="$media:arrow"
ohos:left_margin="15vp"
ohos:right_padding="10vp"
ohos:multiple_lines="true"
ohos:text="CrossFade"
ohos:text_size="12vp"
/>
<Image
ohos:id="$+id:deleteImage"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$media:delete"
ohos:left_margin="10vp"
ohos:padding="13vp"
/>
<Image
ohos:id="$+id:addImage"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$media:add"
ohos:left_margin="25vp"
ohos:padding="15vp"
/>
<Image
ohos:id="$+id:download"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$media:download"
ohos:left_margin="30vp"
ohos:padding="13vp"/>
</DirectionalLayout>
<ListContainer
ohos:id="$+id:listContainer"
ohos:height="match_parent"
ohos:width="match_content"/>
</DirectionalLayout>
(2)设置绑定加载布局
public class MainAbilitySlice extends AbilitySlice {
private MyItemProvider mProvider;
private List<ImageItem> mData;
private ListContainer listContainer;
private Text textType;
enum Type {
CrossFade(new AlphaCrossFadeAnimator()),
FadeIn(new AlphaInAnimator()),
ScaleUp(new ScaleUpAnimator()),
ScaleX(new ScaleXAnimator()),
ScaleY(new ScaleYAnimator()),
SlideDownAlpha(new SlideDownAlphaAnimator()),
SlideLeftAlpha(new SlideLeftAlphaAnimator()),
SlideRightAlpha(new SlideRightAlphaAnimator()),
SlideUpAlpha(new SlideUpAlphaAnimator()
);
private BaseItemAnimator mAnimator;
Type(BaseItemAnimator animator) {
mAnimator = animator;
}
public BaseItemAnimator getAnimator() {
return mAnimator;
}
}
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS);
listContainer = (ListContainer) findComponentById(ResourceTable.Id_listContainer);
listContainer.setWidth(AppUtils.getScreenInfo(this).getPointXToInt());
mData = ImageDummyData.getImages();
mProvider = new MyItemProvider(mData, this, listContainer);
listContainer.setItemProvider(mProvider);
mProvider.setItemAddDuration(200);
mProvider.setRemoveDuration(200);
TableLayoutManager tableLayoutManager = new TableLayoutManager();
tableLayoutManager.setColumnCount(3);
listContainer.setLayoutManager(tableLayoutManager);
mProvider.setItemAnimator(Type.values()[0].getAnimator());
initActionBar();
}
private void initActionBar() {
String[] items = new String[Type.values().length];
ListDialog listDialog = new ListDialog(MainAbilitySlice.this);
listDialog.setAlignment(LayoutAlignment.START | LayoutAlignment.TOP);
listDialog.setSize(400, MATCH_CONTENT);
listDialog.setAutoClosable(true);
for (int i = 0; i < items.length; i++) {
items[i] = Type.values()[i].name();
}
listDialog.setItems(items);
listDialog.setOnSingleSelectListener((iDialog, index) -> {
textType.setText(items[index]);
mProvider.setItemAnimator(Type.values()[index].getAnimator());
iDialog.hide();
});
textType = (Text) findComponentById(ResourceTable.Id_typeText);
textType.setClickedListener(component -> listDialog.show());
findComponentById(ResourceTable.Id_addImage).setClickedListener(component -> {
int visibleIndex = listContainer.getItemPosByVisibleIndex(0);
mProvider.addItem(visibleIndex + 1, ImageDummyData.getDummyItem());
});
findComponentById(ResourceTable.Id_deleteImage).setClickedListener(component -> {
int visibleIndex = listContainer.getItemPosByVisibleIndex(0);
mProvider.removeItem(visibleIndex + 1);
});
findComponentById(ResourceTable.Id_download).setClickedListener(component -> {
int visibleIndex = listContainer.getItemPosByVisibleIndex(0);
mProvider.change(visibleIndex + 1);
});
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
v1.0.0
/*
*Copyright 2018 Mike Penz
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。