Android只能上下拖动

时间:2013-08-05 09:40:49

标签: android

执行Android拖放操作,v是“TextView”,它与屏幕宽度一样宽。

是否可以让“shadowBuilder”只在“向上和向下”拖动而不是“向左和向右”拖动?因为我想要它(“shadowBuilder”或TextView v)在拖动过程中仍然填满整个屏幕宽度。

...谢谢

TextView textDrag;
...

DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v); 
v.startDrag(null, shadowBuilder, v, 0); 



// here is it 
textDrag = (TextView) findViewById(R.id.textDrag);
        LayoutParams p = textDrag.getLayoutParams();
        p.width = displaymetrics.widthPixels * 3;
        textDrag.setLayoutParams(p);
        textDrag.setOnTouchListener(new OnTouchListener(){

            @Override
            public boolean onTouch(View v, MotionEvent motionEvent) {

                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { 
                    //
                    DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v); 
                    v.startDrag(null, shadowBuilder, v, 0);
                    v.setVisibility(View.INVISIBLE); 
                    return true; 

                } else { 
                    return false; 
                } 
            }
        });

0 个答案:

没有答案