DragLinearLayout
DragLinearLayout copied to clipboard
Items with OnClickListener cannot be dragged when inside ScrollView container
I cannot use your library for my custom layout in a draglinearlayout.
Here is my custome layout inflated several times:
<com.mypackage.CustomRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/stationlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/cornerbackground"
android:longClickable="true"
android:clickable="true"
android:focusable="true"
android:paddingBottom="10dp"
android:paddingRight="10dp">
And the scroll view containing the draglinear layout:
<ScrollView
android:id="@+id/scroller"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollcontentcontainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
Nothing happens then, like if the focus was stolen somewhere.
Hi, thanks for opening an issue.
There does indeed seem to be an undesired behavior where items with OnClickListeners within ScrollView containers do not correctly capture the touch and thus cannot be dragged.
I suspect that ScrollView is intercepting the touch before DragLinearLayout does. A potential solution may be to reduce the slop parameter if a container ScrollView is specified, but this will need to be tested.
Meanwhile, a workaround would be to remove the android:clickable and android:longClickable properties from your item layout if you don't need to respond to clicks; if you do need that behavior, you will need to arrange your item layout such that some portion of it (the drag handle) and its parent do not listen for clicks, such as the item layout used in the sample NoteActivity.