我想创建一个应用程序,其中包含一些可以在android studio中拖放的图层图像。任何人有任何想法?
答案 0 :(得分:0)
您必须在所有图像上设置onTouch侦听器,并通过更改图像视图的布局参数来处理onTouch中的拖动。
要隐藏视图,只需检查您的x是否超出屏幕尺寸并更改视图的可见性。
代码只是一个示例
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
final int X = (int) motionEvent.getRawX();
final int Y = (int) motionEvent.getRawY();
int action = motionEvent.getActionMasked();
if(action == MotionEvent.ACTION_DOWN) {
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
xDelta = X - lParams.leftMargin;
yDelta = Y - lParams.topMargin;
Log.i(TAG, "Action down!");
}
if(action == MotionEvent.ACTION_MOVE) {
Log.i(TAG, "Action move!");
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
layoutParams.leftMargin = X - xDelta;
layoutParams.topMargin = Y - yDelta;
layoutParams.rightMargin = -550;
layoutParams.bottomMargin = -250;
view.setLayoutParams(layoutParams);
}
}