DragLinearLayout icon indicating copy to clipboard operation
DragLinearLayout copied to clipboard

Harder to touch the drag handler when inside a long scrollView

Open Tanapruk opened this issue 9 years ago • 4 comments

When the list is short (not scrollable) , it is easy to touch and drag thing around. However, when the list is so long I cannot make a drag. Most of the time, when I try to drag the whole screen is scrolled instead.

I look at your sample it presents no problems. I am confused right now.

Tanapruk avatar Dec 18 '15 14:12 Tanapruk

Hi, thanks for opening an issue.

Could you please provide a snippet of your item layout used for the dragged items? This is likely related to #17.

justasm avatar Dec 18 '15 16:12 justasm

The container layout.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frame1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/relay1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true">
        <include
            android:id="@+id/tool_bar"
            layout="@layout/toolbar_top_sheet_activity" />

        <include
            android:id="@+id/tool_bar_little_title"
            layout="@layout/toolbar_little_title_top_sheet_activity" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_alignBottom="@+id/tool_bar_little_title"
            android:background="@color/lightBlack" />

        <include
            android:id="@+id/tool_bar_bottom"
            layout="@layout/toolbar_bottom_sheet_activity" />

        <ScrollView
            android:id="@+id/scrollview1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@id/tool_bar_bottom"
            android:layout_below="@id/tool_bar_little_title">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <com.jmedeisis.draglinearlayout.DragLinearLayout
                    android:id="@+id/lin0"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                </com.jmedeisis.draglinearlayout.DragLinearLayout>

                <View
                    android:id="@+id/lin1"
                    android:layout_width="match_parent"
                    android:layout_height="96dp"

                    >
                </View>

            </LinearLayout>


        </ScrollView>
    </RelativeLayout>



    <ProgressBar

        android:id="@+id/progressBar1"
        style="?android:progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"


        android:indeterminate="true"
        android:visibility="gone" />
</FrameLayout>

The item and its handler.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/container_big"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">
        <LinearLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="@dimen/height"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/number"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="bottom"
                android:layout_weight="8"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="end|center_vertical"
                android:lines="1"
                android:longClickable="true"
                android:maxLength="13"
                android:singleLine="true"
                android:textSize="@dimen/text_size_normal" />

            <EditText
                android:id="@+id/note"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="bottom"
                android:layout_weight="6"
                android:background="@null"
                android:ems="6"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="end|center_vertical"
                android:inputType="textNoSuggestions"
                android:longClickable="true"
                android:maxLength="45"
                android:paddingLeft="@dimen/padding_left_et_note"
                android:paddingRight="@dimen/rpadding_right_et_note"

                android:selectAllOnFocus="false"
                android:singleLine="true"
                android:textColor="@color/grey600"
                android:textSize="@dimen/text_size_normal"
                />


        </LinearLayout>

        <ToggleButton

            android:id="@+id/tb_record_sign"
            android:layout_width="@dimen/record_icon_size"
            android:layout_height="@dimen/record_icon_size"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/record_padding_margin_left_right"
            android:background="@drawable/check"
            android:textOff=""
            android:textOn=""

            />

        <ImageButton
            android:id="@+id/ib_record_calc"
            android:layout_width="@dimen/record_icon_size"
            android:layout_height="@dimen/record_icon_size"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/record_icon_margin_left"
            android:focusable="true"
            android:paddingBottom="@dimen/icon_padding_bigger"
            android:paddingLeft="@dimen/icon_padding_bigger"
            android:paddingRight="@dimen/icon_padding_bigger"
            android:paddingTop="@dimen/icon_padding_bigger"
            android:scaleType="fitCenter"
            android:src="@mipmap/ic_calc"
            android:visibility="invisible" />


        <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/view_drag_handle"
            android:layout_width="@dimen/record_icon_size_big"
            android:layout_height="@dimen/record_icon_size_big"
            android:layout_alignParentRight="true"
            android:layout_marginRight="@dimen/record_padding_right"
            android:adjustViewBounds="true"
            android:contentDescription="@string/hint_move"
            android:paddingBottom="@dimen/record_icon_padding_inside_big"
            android:paddingRight="@dimen/record_icon_padding_inside"
            android:paddingTop="@dimen/record_icon_padding_inside_big"
            android:src="@drawable/ic_move_record"
            android:visibility="visible">

        </ImageView>



        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_alignBottom="@id/container_cv_record"
            android:background="@color/lightBlack" />

    </RelativeLayout>

The view_drag_handle can be toggled to be a remove button. I am not sure this is related but seeing the issue #17 is related to click things.

view_drag_handle is used as a drag handler to move big_container inside the lin0

Tanapruk avatar Dec 18 '15 17:12 Tanapruk

Thanks for providing more context for the issue. I will look into it (and invite any contributors to do the same).

As a side note, I would not recommend using DragLinearLayout for such a use case where the entire scrollable content is a collection of (potentially very many) swappable items. An official, modern, well-documented and extensible solution to this is using a RecyclerView with ItemTouchHelper to provide drag and drop support. You can find a good overview and tutorial here.

justasm avatar Dec 18 '15 21:12 justasm

Other solution might be to disable the scroll. Just get a CustomSwipeView, which overrides touch events (e.g. here). Now add a menu button or similar and let the user choose if he wants to edit or use the scrollview in it's default behaviour. In my case this solution provides a suitable interaction with the app.

By the way: Thanks for this awesome library, justasm. It's really great. Good work!

pepperonas avatar Jun 19 '16 12:06 pepperonas