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

标签 android 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>

最佳答案

这是一种方法

1) 向支持拖动的ListView注册一个OnItemClickListener(我将这个ListView称为ListViewA)

2)在ListViewA的OnItemClickListener中记录当前被拖动的item。还设置一些状态变量以指示正在发生拖动。

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

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

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

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

额外内容: 您可以添加动画,以便在项目被放入之前在 ListViewB 中出现幻影项目。您还可以通过覆盖自定义 LinearLayout 类中的 onDraw 函数来绘制正在拖动的项目。

关于android - 在具有图像和向后兼容性的两个 ListView 之间拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27574052/

相关文章:

android - 在 Kotlin 中支持 Lollipop

java - 如何从选定的联系人中提取电话号码?

java - 在 ListView 中显示 POJO 对象的多个字段

android - 将 SeparatedListAdapter 用于 ListView 在 Android 2.1 上崩溃但适用于 2.2

java - 在我的 ArrayList 上保存项目(添加不断替换第一个)

android - Root VS 权限

java - 无法在后端看到存储的数据(Parse.com)

android - 使用 RelativeLayout 时工具栏出现在布局顶部

android - 如何对合并光标进行排序?

android - ListView 平滑滚动,直到项目位于顶部