Android控件用于简单的拖放框

Android控件用于简单的拖放框,第1张

概述我想在应用程序的顶部有一行项目,每个框内都有一个图标或一个字母.您可以按任何顺序水平排列它们.真的很容易交换,而不是像握住然后移动.我会用什么样的控制? 首先让我澄清一下这个任务.您是否只需要水平列表中的一组预定义项目(选项A)? 或者滚动的水平列表(选项B): 让我们暂时假设选项A是相关的,所以你需要: >水平清单实施 >适当的拖放处理 步骤1 有几个水平列表实现可用,但其中一些是旧的,不支持, 我想在应用程序的顶部有一行项目,每个框内都有一个图标或一个字母.您可以按任何顺序水平排列它们.真的很容易交换,而不是像握住然后移动.我会用什么样的控制?解决方法 首先让我澄清一下这个任务.您是否只需要水平列表中的一组预定义项目(选项A)?

或者滚动的水平列表(选项B):

让我们暂时假设选项A是相关的,所以你需要:

>水平清单实施
>适当的拖放处理

步骤1

有几个水平列表实现可用,但其中一些是旧的,不支持,所以我建议检查Horizontal Variable ListView:

Horizontal ListVIEw for AndroID. Based on the official ListVIEw Google
code. It supports almost all the features of the ListVIEw Widget.
There are minor differences in the attributes supported like
“divIDerWIDth” instead of the default “divIDerHeight”.

BTW它支持AndroID 4.2.2,另请参阅demo example.

第2步

此时您实际需要的只是正确处理拖放 *** 作.

最简单的解决方案是遵循音乐应用程序中使用的标准和众所周知的示例:TouchInterceptor class.它扩展了ListVIEw,因此使用与Horizontal Variable ListView相同的方法应该不会有问题.

特别注意:

public boolean onIntercepttouchEvent(MotionEvent ev) {

public boolean ontouchEvent(MotionEvent ev) {

第3步:高级实施

我个人认为选项A只能用作演示,所以你必须解决滚动问题.上面的示例显示了如何处理滚动,但可能需要更多一些.

还有另一个项目(再次停产)可用作高级示例,因为它解决了几个问题,支持动画等:

07004 is an extension of the AndroID ListVIEw that
enables drag-and-drop reordering of List items. It is a major overhaul
complete rewrite of the touchInterceptor (TI) meant to give
drag-sorting a polished feel. Some key features are:

Clean drag and drop Intuitive and smooth scrolling while dragging. Support for heterogeneous item heights. Public startDrag() and stopDrag() methods. Public interface for customizing the floating VIEw.

DragSortListVIEw is useful for all kinds of prioritized Lists:
favorites,playLists,checkLists,etc.

它似乎记录良好且易于理解.从垂直模式切换到水平模式不应该那么难.

public class DragSortListVIEw extends ListVIEw {    /**     * The VIEw that floats above the ListVIEw and represents     * the dragged item.     */    private VIEw mfloatVIEw;    /**     * The float VIEw location. First based on touch location     * and given deltaX and deltaY. Then restricted by callback     * to floatVIEwManager.onDragfloatVIEw(). Finally restricted     * by bounds of DSLV.     */    private Point mfloatLoc = new Point();    private Point mtouchLoc = new Point();    /**     * The mIDdle (in the y-direction) of the floating VIEw.     */    private int mfloatVIEwMID;    /**     * Flag to make sure float VIEw isn't measured twice     */    private boolean mfloatVIEwOnMeasured = false;    /**     * Watch the Adapter for data changes. Cancel a drag if     * coincIDent with a change.     */     private DataSetobserver mObserver;    /**     * Transparency for the floating VIEw (XML attribute).     */    private float mfloatAlpha = 1.0f;    private float mCurrfloatAlpha = 1.0f;    /**     * While drag-sorting,the current position of the floating     * VIEw. If dropped,the dragged item will land in this position.     */    private int mfloatPos;
总结

以上是内存溢出为你收集整理的Android控件用于简单的拖放框全部内容,希望文章能够帮你解决Android控件用于简单的拖放框所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1129948.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存