# DragListView **Repository Path**: chinasoft_ohos/DragListView ## Basic Information - **Project Name**: DragListView - **Description**: 实现ListContainer多级滑动及自动居中 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 3 - **Created**: 2021-04-23 - **Last Updated**: 2024-11-08 ## Categories & Tags **Categories**: harmonyos-listview **Tags**: None ## README # DragListView #### 项目介绍 + 项目名称:DragListView + 所属系列:openharmony的第三方组件适配移植 + 功能:实现ListContainer多级滑动及自动居中 + 项目移植状态:内部拖动排序暂不支持 + 调用差异:如有多级ListContainer嵌套,最外层请用BaseListContainer,已处理掉不同方向的滑动冲突与内部Item自动居中的效果 + 开发版本:sdk6,DevEco Studio2.2 Beta1 + 基线版本:Release v1.7.1 #### 效果演示 ![输入图片说明](https://gitee.com/chinasoft_ohos/DragListView/raw/master/gif/1.gif "1.gif") #### 安装教程 1.在项目根目录下的build.gradle文件中, ```txt allprojects { repositories { maven { url 'https://s01.oss.sonatype.org/content/repositories/releases/' } } } ``` 2.在entry模块的build.gradle文件中, ```txt dependencies { implementation('com.gitee.chinasoft_ohos:DragListView:1.0.0') ...... } ``` 在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 #### 使用说明 library中自定义了几个控件,如果有需要ListContainer嵌套ListContainer不同方向滑动,例如外部横向滑动,内部纵向滑动,外部的ListContainer可用BaseListContainer,在BaseListContainer中已处理掉滑动冲突 ```txt @Override public void onDragUpdate(Component component, DragInfo dragInfo) { // dragInfo.xOffset为正数代表正在向右滑 负数则为向左滑 scrollBy(-(int) dragInfo.xOffset, 0); } ``` 还有一个自定义的类:BaseDependentLayout,支持Item左右滑动,左滑可出现新的布局(用户自定义)二次左滑将上一个左滑的Item还原,右滑删除,和点击的背景变色的点击效果,内部有较多的设置 如果需要支持左右滑动请在外部调用一下代码并设置为true ```txt public void setSlide(boolean isB) { this.isSlide = isB; } ``` 若是在ListContainer的Item中使用,请将外部ListContainer设置进来,此处作用是在左右滑动时可以将外部ListContainer的上下滑动屏蔽,避免上下左右一起滑动 ```txt public void setListContainer(ListContainer listContainer) { this.listContainer = listContainer; } ``` 如若需要二次左滑还原上一个Item,请设置回调接口,接口中的方法会帮助你来更方便实现效果, component用来判断是否与上一个滑动的一致,一致就将上一个还原,否则就不执行本次滑动,action用来判断本次滑动手势 ```txt public void setObserver(MyObserver observer) { this.observer = observer; } public interface MyObserver { /** * 自定义观察者,可在BaseDepend中注册,会在左右滑动结束后回调 * * @param component * @param action */ void response(BaseDependentLayout component, int action); } ``` 另外,可以在Java类中设置按下和抬起的背景 ```txt public void setStartElement(ShapeElement element) { mGrayShapeElement = element; } public void setEndElement(ShapeElement element) { mWhiteShapeElement = element; } ``` #### 测试信息 CodeCheck代码测试无异常 CloudTest代码测试无异常 病毒安全检测通过 当前版本demo功能与原组件基本无差异 #### 版本迭代 - 1.0.0 #### 版权和许可信息 Copyright 2014 Magnus Woxblom 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.