gpt4 book ai didi

android:如何通过拖放将小部件移动到图形屏幕中的特定位置

转载 作者:行者123 更新时间:2023-11-29 22:20:12 25 4
gpt4 key购买 nike

我是 android 开发的新手,请赐教如何通过拖放将按钮、 TextView 等小部件移动到图形屏幕中的特定位置..

提前致谢

阿克沙特

最佳答案

尝试以下代码:-

int x_cord, y_cord;
RelativeLayout.LayoutParams layoutParams1;

@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (v == mImageViewEye1) {
System.out.println("Eye1 is Clicked...");
layoutParams1 = (RelativeLayout.LayoutParams) mImageViewEye1
.getLayoutParams();
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
x_cord = (int) event.getRawX();
y_cord = (int) event.getRawY();
scaleimage(layoutParams1);
layoutParams1.topMargin = y_cord - 75;
mImageViewEye1.setLayoutParams(layoutParams1);
break;
default:
break;
}
}
return true;
}

public void scaleimage(RelativeLayout.LayoutParams layoutParams) {
if (x_cord > windowwidth) {
x_cord = windowwidth;
}
if (y_cord > windowheight) {
y_cord = windowheight;
}
layoutParams.leftMargin = x_cord - 25;
layoutParams.topMargin = y_cord - 75;
}

如果您有任何疑问,请告诉我。

关于android:如何通过拖放将小部件移动到图形屏幕中的特定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7441249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com