首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用向下滑动手势删除水平滚动视图中的项目?

问如何使用向下滑动手势删除水平滚动视图中的项目?
EN

Stack Overflow用户
提问于 2017-11-05 15:33:58
回答 1查看 391关注 0票数 0

我有这个项目的App demo video,需要在水平滚动视图中添加6种类型的图像,每个都会有对话片段。如何在水平滚动视图中找到图像的位置,并在滑下时删除视图。

代码语言:javascript
复制
final String[] AddCustomitems = {"Blink single message", "Blink double message", "Message", "Scroll", "Split", "Temp"}; //list of items that can be added in layout
int[] customviewsDrawable = new int[]{R.drawable.custom_blink, R.drawable.custom_blink_double, R.drawable.custom_message, R.drawable.custom_scroll, R.drawable.custom_split_double, R.drawable.temp};


public void CustomAnimationList(final Activity activity) {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    //set the title for alert dialog
    builder.setTitle("Dot Matrix Add view");
    //set items to alert dialog. i.e. our array , which will be shown as list view in alert dialog
    builder.setItems(AddCustomitems, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int item) {
            // setting the button text to the selected item from the list
            AddItem(item);
        }
    });

    //Creating CANCEL button in alert dialog, to dismiss the dialog box when nothing is selected
    builder.setCancelable(false)
           .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
                    //When clicked on CANCEL button the dalog will be dismissed
                    dialog.dismiss();
                }
            });
    // Creating alert dialog
    AlertDialog alert = builder.create();
    //Showing alert dialog
    alert.show();
}

     void AddItem(final int itemNum) {
                if (countItem < 9) {
                    final float scale = getResources().getDisplayMetrics().density;
                    int dpWidthInPx = (int) (175 * scale); //rescalling views
                    int dpHeightInPx = (int) (250 * scale); //rescalling views
                    final LinearLayout sv = (LinearLayout) findViewById(R.id.horizontalLayout);
                    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(dpWidthInPx, dpHeightInPx);
                    layoutParams.setMargins(10, 0, 0, 10); //adding margin
                    final ImageView iv = new ImageView(this);
                    iv.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            alertView(itemNum); //this will send  itemNum to switch case for corresponding dialog fragment.
                        }
                    });
                    iv.setLayoutParams(layoutParams);
                    iv.setBackgroundResource(customviewsDrawable[itemNum]);
                    sv.addView(iv);
                    countItem++;
                } else {
                    alertItem(); //alert message if items are more then 8
                }
                System.out.println("count items :" + countItem);
            }
EN

回答 1

Stack Overflow用户

发布于 2017-11-26 14:41:09

我已经使用ItemTouchHelper类实现了这一点,我还添加了一些功能

1)在水平滚动视图中添加自定义多个对话框片段。

2)上下滑动时,拖放功能可移动或删除项目

3)列出按下按钮时的项目顺序

4)如果项目超过8个元素,则提示对话框。

我已经在github上提交了代码,任何人都可以试用。[https://github.com/parmarravi/HorizontalRecyclerView]

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47119261

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档