在具有图像和向后兼容性的两个ListView之间拖放

Aur*_*tas 10 android listview

我正在寻找在具有图像向后兼容性的两个 ListView 之间进行拖放的方式。

例:

http://i.imgur.com/DVBdlcc.png

布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

    <LinearLayout
       android:orientation="horizontal"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:splitMotionEvents="true">
        <TextView
           android:layout_width="0dip"
           android:layout_height="match_parent"
           android:text="list 1"
           android:layout_weight="1"
           android:textSize="25sp"
           android:gravity="center" />
        <TextView
           android:layout_width="0dip"
           android:layout_height="match_parent"
           android:text="list 2"
           android:layout_weight="1"
           android:textSize="25sp"
           android:gravity="center" />
    </LinearLayout>

    <LinearLayout
       android:orientation="horizontal"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:splitMotionEvents="true">
        <ListView android:id="@+id/list1"
           android:layout_width="0dip"
           android:layout_height="match_parent"
           android:layout_weight="1"
           android:paddingBottom="0sp"/>
        <ListView android:id="@+id/list2"
           android:layout_width="0dip"
           android:layout_height="match_parent"
           android:layout_weight="1" />
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

idu*_*olz 8

这是一种方法

1)OnItemClickListenerListView支持拖动的上注册一个(我将其ListView称为ListViewA)

2)在OnItemClickListenerListViewA的中,记录当前正在拖动的项目。还要设置一些状态变量以指示发生拖动。

3)拦截ListViewA的父级的touch事件(执行此操作的一种方法是创建一个自定义类,将其扩展LinearLayout,然后覆盖onInterceptTouchEvent()onTouchEvent),并记录用户将项目拖动到何处。

4)进行绑定检查,以查看用户是否将项目拖到ListView接受拖放的项目中(我将其ListView称为ListViewB)。

5)如果是,请进行更详细的检查,以查看ListViewB的项目介于哪两个之间。

6)将另一个项目添加到ListViewB的适配器中,该适配器将显示一个放置指示器(向用户指示放置位置)。

附加功能:您可以添加动画,以便在放置项目之前将幽灵项目显示在ListViewB中。还可以通过重写自定义LinearLayout类中的onDraw函数来绘制拖动项目时所放置的项目。