请教一下listcontainer怎么设置item的左右滑动事件?

listcontainer
2021-09-22 22:46:12
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
红叶亦知秋
5

item的左右滑动,楼主可以尝试下设置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;
                }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
已于2021-9-24 17:06:05修改
分享
微博
QQ
微信
回复
2021-09-24 16:13:20


相关问题
请教一下如何实现函数重载
1779浏览 • 1回复 待解决
请教一下关于Ticktimer 疑问?
4277浏览 • 1回复 待解决
请教一下如何开关闪光灯
1493浏览 • 1回复 待解决
请教一下关于应用分栏实现
1972浏览 • 1回复 待解决
请教2个vp相关问题,麻烦解答一下
1054浏览 • 1回复 待解决