从活动拖动查看,并在新的Andr​​oid碎片砸 [英] Drag View from Activity and drop it in new Fragment android

查看:183
本文介绍了从活动拖动查看,并在新的Andr​​oid碎片砸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现一个拖放在我的应用程序,我从我的活动拖动视图,我要砸在那一刻开始拖动创造了新的片段,但不要在片段的工作将监听器我用的是下一个code在我的活动:

i try to implement a Drag and Drop in my app, I drag the view from my Activity, and i want drop it in new Fragment created in the moment when drag start, but don't work the Drag Listener in the Fragment, i use the next code in my activity:

    findViewById(R.id.button1).setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            vibra();
            ClipData data = ClipData.newPlainText("", "");
            DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
            view.startDrag(data, shadowBuilder, view, 0);

            FragmentShare share = new FragmentShare(getSupportFragmentManager());
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.add(R.id.principal, share);
            ft.addToBackStack(null);
            ft.commit();

            return false;
            }
        });

在我的片段中的code是下一个:

And the code in my fragment is the next:

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View vv = inflater.inflate(R.layout.fragment_share, container, false);

    vv.findViewById(R.id.button1).setOnDragListener(new OnDragListener() {
        @Override
        public boolean onDrag(View v, DragEvent event) {
            int action = event.getAction();
            switch (action) {
                case DragEvent.ACTION_DRAG_STARTED:
                    break;
                case DragEvent.ACTION_DRAG_ENTERED:
                    v.setEnabled(false);
                    break;
                case DragEvent.ACTION_DRAG_EXITED:
                    v.setEnabled(true);
                    break;
                case DragEvent.ACTION_DROP:
                    manager.popBackStackImmediate();
                    break;
                case DragEvent.ACTION_DRAG_ENDED:
                    manager.popBackStackImmediate();
                    break;
                default:
                    break;
            }
            return true;
        }
    });

    return vv;
}

但视图状态不会改变,当下降的观点不退缩。
我不知道这是否其可能与否,还是有实现这个请告诉我这是什么其他的方式。

But the view state never change and don't back when drop the view. I don't know if this its possible or not, or have other way to implement this please tell me what is this.

感谢。

钯。对不起,我的英语水平。

Pd. Sorry for my english.

推荐答案

如果您的应用程序的最小SDK版本是11,那么这个作品,

If your application's min sdk version is 11, then this works,

我们有getter和setter方法​​X,Y坐标,宽度和视图的高度。
使用这些方法,我们可以将一个视图中的所有在屏幕上。

We have getters and setters for X,Y coordinates , width and height of a view. Using these methods, we can move a view all over the screen.

所以,我完成什么你的任务是,

So, what i do to accomplish your task is,

1)我开始更新视图的onTouchListener视图的x位置。
2)当我启动,同时我创建了一个片段。
3)当我的观点达到片段我会完成()的活性,并添加相同的布局,以片段。

1) I start updating x position of a view in onTouchListener of the view. 2) As soon as i start, simultaneously i create a fragment. 3) When my view reaches the fragment i will finish() the activity and add the same layout to the fragment.

在这种方式,我们可以illute。

In this way we can illute.

希望这有助于..

这篇关于从活动拖动查看,并在新的Andr​​oid碎片砸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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