使用图像和向后兼容性在两个ListView之间拖放

时间:2014-12-19 21:20:18

标签: android listview

我正在搜索拖放 两个 ListViews 图片向后兼容性<的方式/强>

示例:

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>

1 个答案:

答案 0 :(得分:8)

这是一种做法

1)使用支持拖动的OnItemClickListener注册ListView(我将此ListView称为ListViewA)

2)在ListViewA的OnItemClickListener中,记录当前被拖动的项目。还设置一些状态变量以指示正在进行拖动。

3)拦截ListViewA父级的触摸事件(这样做的一种方法是创建一个扩展LinearLayout然后覆盖onInterceptTouchEvent()onTouchEvent的自定义类)并记录用户正在拖动该项目。

4)进行绑定检查以查看用户是否将项目拖入接受删除的ListView(我将此ListView称为ListViewB)。

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

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

附加功能: 您可以添加动画,以便在项目被放入之前在ListViewB中显示重影项。您还可以通过覆盖自定义LinearLayout类中的onDraw函数来绘制被拖动项目。