首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓DragLinearLayout不能正常工作,拖放效果不佳,或者拖拽图片效果不佳

问安卓DragLinearLayout不能正常工作,拖放效果不佳,或者拖拽图片效果不佳
EN

Stack Overflow用户
提问于 2018-04-11 08:18:05
回答 1查看 221关注 0票数 1

我正在使用this library

我正在编程添加ImageViews,但图像几乎不能拖动。它需要很长时间的按压,有时有效,有时无效。

这是加法函数

Java

代码语言:javascript
复制
private ScrollView llCanvusContainer;
private DragLinearLayout llCanvus;
llCanvus = (DragLinearLayout)findViewById(R.id.llCanvus);
llCanvusContainer = (ScrollView)findViewById(R.id.llCanvusContainer);
llCanvus.setContainerScrollView(llCanvusContainer);

private void appendImageToLinearLayout(DragLinearLayout layout,
                                           ParseFile parseFileImage,
                                           int w, int h,
                                           boolean fullWidth,
                                           boolean isPostImage,
                                           final int position)
            throws ParseException, IOException {

        ImageView imageView= new ImageView(this);
        //imageView.setBackgroundResource(R.drawable.ic_action_search);
        imageView.setImageBitmap(

                ImageTools.
                        getBitmapFromUri(Uri.fromFile(
                                parseFileImage.getFile()),
                                this, fullWidth
                        )
        );

        // params
        //DragLinearLayout.LayoutParams viewParamsCenter =
                new DragLinearLayout.LayoutParams(
                        w,
                        h);
        //viewParamsCenter.gravity = Gravity.CENTER_HORIZONTAL | Gravity.RIGHT;

        //imageView.setLayoutParams(viewParamsCenter);
        imageView.setId(position);
        imageView.setContentDescription(imageList.get(position).getObjectId());
        layout.addDragView(imageView, imageView);

        //layout.setViewDraggable(imageView, imageView);

        if(isPostImage){

            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //showImageFullScreen(position);
                    Toast.makeText(EditPostActivity.this, "clicked " + v.getId(), Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

下面是我如何添加图像视图

代码语言:javascript
复制
        for (ParseObject imgObj : imageList) {

            // add the image to the linear layout
            appendImageToLinearLayout(
                    llCanvus,
                    imgObj.getParseFile("image"),
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    true,
                    true,
                    i
            );

XML

代码语言:javascript
复制
<ScrollView
    android:id="@+id/llCanvusContainer"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginTop="8dp"
    android:background="@android:color/white"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/switchIsPublic">

    <com.jmedeisis.draglinearlayout.DragLinearLayout
        android:id="@+id/llCanvus"
        style="@style/Gallery19crollbarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/switchIsPublic" />

</ScrollView>

图像显示正确,但拖动不能正常工作。

编辑

当我删除ScrollView时,拖放工作正常。

EN

回答 1

Stack Overflow用户

发布于 2018-04-11 09:48:34

如果你不介意使用recyclerView,那么你可以愉快地使用ItemTouchHelper。

我使用ItemTouchHelper对我的列表进行重新排序,它工作得很好。

这是我找到的blog post

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

https://stackoverflow.com/questions/49764592

复制
相关文章

相似问题

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