我怎么能水平拖动一个看法

我怎么能水平拖动一个看法

本文介绍了我怎么能水平拖动一个看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在像ListView和画廊你可以在一个方向纵向或横向拖动项目的控制。

In controls like ListView and Gallery you can drag items in one direction vertical or horizontal.

我有我拖累了它成功一个TextView。但我想将它移到水平方向。我怎么能实现呢?

I have a TextView that I drag it successfully. But I want to move it in horizontal direction. how can i implement it?

谢谢,

我的code:

public class MyDragShadowBuilder extends View.DragShadowBuilder {
    private static View view;

    public MyDragShadowBuilder(View v) {
        super(v);
        view = v;
    }

    @Override
    public void onProvideShadowMetrics(Point size, Point touch) {
        width = getView().getWidth();
        height = getView().getHeight();
        size.set(width, height);
        touch.set(width / 2, height / 2);
    }

    private int width, height;

    @Override
    public void onDrawShadow(Canvas canvas) {
        view.draw(canvas);
    }
}

在我的活动:

tv.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            ClipData data = ClipData.newPlainText("dot",
                    "Dot : " + v.toString());
            View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v);
            v.startDrag(data, myShadow,(Object) v, 0);
            return false;
            }
        });

我要模拟一个画廊。我有10000照片通过它来展示。我的画廊可以显示10张照片。我想拖我的库在水平方向包含库的内容和当的LinearLayout达到像SlidingDrawer窗口结束时,改变其内容,并显示下一个10张的的LinearLayout。 SlidingDrawer是一个很好的解决方案,但它有一定的局限性。当你设置你的整个的LinearLayout作为它的句柄不能点击它。当您设置一个分隔的处理作为它,你不能确定位置的处理相对内容

I want to simulate a Gallery. I have 10000 photos to show by it. My gallery can show 10 photos. I want to drag the LinearLayout of my gallery which is containing the gallery's content horizontally and when the LinearLayout reached to the end of window like SlidingDrawer, change its content and show the next 10 photos. SlidingDrawer is a good solution but it has some limitations. When you set your whole LinearLayout as its handle it can not be clicked. When you set a separated handle for it, you can not determine the position of handle relative to the content.

推荐答案

如果你想滚动使用水平滚动视图由其他建议。

If you want to Scroll the use the Horizontal scroll view as suggested by the rest.

但如果你的意思是阻力,如拖放,那么你可以做以下。

But if you mean drag as in "drag and drop" then you can do the following.


  • 设置了触摸监听器上的的TextView

  • 接听所有事件后, ACTION_DOWN 和活动 ACTION_MOVE

  • 获得 X 从上面的事件是位置

  • 使用API​​ 机顶盒 setLeft ,并将其设置为 X 您在上面获得

  • 然后调用无效对整个视​​图

  • Set up a touch listener on the TextView
  • Listen to all events after ACTION_DOWN and events ACTION_MOVE
  • Get the x and y position from the above events
  • use the API setTop and setLeft and set them to x and y you get above
  • then call invalidate on the whole view

这应该拖动UI元素在屏幕上。

This should drag the UI element around the screen.

这篇关于我怎么能水平拖动一个看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:16