gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:06:56 25 4
gpt4 key购买 nike

我正在寻找在两个带图像向后兼容性之间拖放的方法>.

例子:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com