请教一下,listcontainer怎么设置item的滑动事件?是哪个方法?

请教一下,listcontainer怎么设置item的滑动事件?是哪个方法?
 

鸿蒙
HarmonyOS
OpenHarmony
2021-10-29 09:39:26
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
babblue

tem的左右滑动,楼主可以尝试下设置setDraggedListener,代码样例如下

private Point componentpoint;

convertView.setDraggedListener(Component.DRAG_HORIZONTAL,new Component.DraggedListener() {

                @Override

                public void onDragDown(Component component, DragInfo dragInfo) {

                        LogUtil.info(TAG,"---onDragDown---"+dragInfo.downPoint.getPointX());

                }

                @Override

                public void onDragStart(Component component, DragInfo dragInfo) {

                    LogUtil.info(TAG,"---onDragStart---"+dragInfo.startPoint.getPointX());

                    pointStart = dragInfo.startPoint;

                    LogUtil.info(TAG,"onDragStart::component.getContentPositionX():"+component.getContentPositionX());

                    componentpoint = new Point(component.getContentPositionX(),component.getContentPositionY());

                }

                @Override

                public void onDragUpdate(Component component, DragInfo dragInfo) {

                    LogUtil.info(TAG,"---onDragUpdate---"+dragInfo.updatePoint.getPointX());

                    float xOffset = dragInfo.updatePoint.getPointX() - pointStart.getPointX();

                    LogUtil.info(TAG,"onDragUpdate::component.getContentPositionX():" + component.getContentPositionX());

                    if((componentpoint.getPointX() + xOffset) > 0 ) {

                        component.setContentPosition(componentpoint.getPointX() + xOffset, componentpoint.getPointY());

                        componentpoint = new Point(component.getContentPositionX(),component.getContentPositionY());

                    }

                }

                @Override

                public void onDragEnd(Component component, DragInfo dragInfo) {

                    float xOffset = dragInfo.updatePoint.getPointX() - pointStart.getPointX();

                    LogUtil.info(TAG,"onDragEnd::xOffset:" + xOffset);

                    if((componentpoint.getPointX() + xOffset) > 0 && (componentpoint.getPointX() + xOffset) < screenWidth / 2) {

                        component.setContentPosition(0, componentpoint.getPointY());

                    } else if ((componentpoint.getPointX() + xOffset) > 0 && (componentpoint.getPointX() + xOffset) >=  screenWidth / 2) {

                        deleteItem(position);

                    }

                    LogUtil.info(TAG,"onDragEnd::componentpoint.getPointX():"+componentpoint.getPointX());

                }

                @Override

                public void onDragCancel(Component component, DragInfo dragInfo) {

                    LogUtil.info(TAG,"---onDragCancel---"+dragInfo.updatePoint+"::"+dragInfo.xOffset);

                }

                @Override

                public boolean onDragPreAccept(Component component, int dragDirection) {

                    return true;

分享
微博
QQ
微信
回复
2021-10-29 16:36:14
相关问题
请教一下关于Ticktimer 疑问?
1571浏览 • 1回复 待解决
ListContainerItem能取消拖拽吗
3462浏览 • 1回复 待解决
鸿蒙注销当前页面哪个方法
6902浏览 • 1回复 已解决
一下 ArkTS中math库个?
816浏览 • 2回复 待解决
同意取消弹窗怎么实现?用哪个方法
3086浏览 • 1回复 待解决
ob有如何报错,麻烦帮忙看一下
2814浏览 • 1回复 待解决
如何屏蔽List滑动事件
301浏览 • 1回复 待解决
能否审核一下传上去文档
1054浏览 • 5回复 待解决
请问一下鸿蒙pad应用该如何签名?
6256浏览 • 1回复 待解决