我想在拖动时更改textview位置 触摸事件对我来说很有助于创造阴影。
textview.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
//ClipData data = ClipData.newPlainText(textview.getText(),textview.getText());
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(textview);
textview.startDrag(null,shadowBuilder,textview,0);
return true;
}
return false;
}
});
但是在拖动事件结束后,阴影会移回原始状态,但我需要将textview设置为阴影区域
我不想复制或创建textview的副本。
答案 0 :(得分:0)
我终于使用了代码,但在textview和shadow
中遇到了一些位置问题textview.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
int x = (int)event.getX();
int y = (int)event.getY();
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(x, y, 0, 0);
textview.setLayoutParams(layoutParams);
return true;
}
});