Android的控制,简单的拖放盒 [英] Android control for simple drag and drop boxes

查看:113
本文介绍了Android的控制,简单的拖放盒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有1号线项目在应用程序的顶部,里面的每个框将有一个像图标或字母。你可以安排他们在任何顺序,水平。真的很容易掉,不喜欢抱,然后移动。我会用这个什么样的控制?

I want to have 1 line of items at the top of the app, inside each box will have like an icon or a letter. You can arrange them in any order, horizontally. Really easy to swap, not like hold and then move. What kind of control would I use for this?

推荐答案

首先我要澄清的任务了一下。你只需要一个predefined水平列表中设置项目的(选项A)的?

First of all let me clarify the task a bit. Do you need just a predefined set of items in the horizontal list (option A)?

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

让我们假设了片刻选项A 是相关的,所以你需要:

Let's assume for a moment option A is relevant, so you'll need:

  1. 水平列表实施
  2. 在适当的拖放操作

第1步

有几个水平列表实现可用,但他们中的一些是旧的和不支持的,所以我建议要检查水平变量的ListView

There are several horizontal list implementations available, but some of them are old and unsupported, so I'd suggest to check Horizontal Variable ListView:

水平的ListView为Android。根据官方公布的ListView谷歌   code。它支持的ListView控件的几乎所有功能。   有支持像在属性细微差别   dividerWidth,而不是默认的dividerHeight。

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".

顺便说一句,它支持安卓4.2.2 ,请参见<一href="https://github.com/sephiroth74/HorizontalVariableListView/blob/master/Demo/src/it/sephiroth/android/sample/horizontalvariablelistviewdemo/MainActivity.java">demo例如

BTW it supports Android 4.2.2, please also see demo example.

第2步

你真正需要什么,在这一点上只是为了妥善处理拖放操作。

What you actually need at this point is just to handle drag and drop actions properly.

最简单的解决办法是遵循标准和众所周知的例子:<一href="https://github.com/android/platform_packages_apps_music/blob/master/src/com/android/music/TouchInterceptor.java">TouchInterceptor类在音乐应用程序中使用。它扩展了的ListView 所以它不应该是一个问题,使用与水平变量的ListView同样的方法

The simplest solution is to follow standard and well-known example: TouchInterceptor class used in the Music application. It extends ListView so it should not be a problem to use the same approach with Horizontal Variable ListView.

特别注意:

public boolean onInterceptTouchEvent(MotionEvent ev) {

public boolean onTouchEvent(MotionEvent ev) {

第3步:高级执行

我个人认为选项A 只能作为演示,所以你必须要解决的滚动问题为好。上面的例子显示如何处理滚动,但它可能是你需要多一点的情况。

Personally I think option A can only be used as a demo, so you have to address scrolling problem as well. Examples above show how to handle scrolling, but it might be a case you need a bit more.

还有另一个项目(再次中止),它可以被用来作为一种先进的例子,因为它解决了一些问题,支持动画等

There is another project (discontinued again) which can be used as an advanced example, because it solves several issues, supports animation, etc:

DragSortListView(DSLV)是Android的ListView的扩展,   使列表项目拖动和放下重排序。这是一个重大改革   在TouchInterceptor的完全重写(TI)为了给   拖选一个抛光的感觉。一些主要特点是:

DragSortListView (DSLV) 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:

      
  • 清洁拖放
  •   
  • 直观和平滑滚动的同时拖动。
  •   
  • 支持异构项目的高度。
  •   
  • 在公共的startDrag(),并调用stopDrag()方法。
  •   
  • 在公共接口用于自定义浮动视图。
  •   
  • 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是各种优先列表有用:   收藏夹,播放清单,清单等。

DragSortListView is useful for all kinds of prioritized lists: favorites, playlists, checklists, etc.

这似乎是很好的归档并且易于理解。从纵向切换到横向模式不应该是那么难。

It seems to be well-documented and easy to understand. Switch from vertical to horizontal mode should not be that hard.

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的控制,简单的拖放盒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆