我有2个图像和一个可以更靠近地移动图像的按钮。现在我需要获得一个文本字段以显示两个图像之间的距离(以像素为单位)。因此,标签可以显示图像距离彼此20个像素,或者如果我移动图像更接近文本字段将显示19个像素。显示图像的距离测量
这里是我现在的代码
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ViewGroup.MarginLayoutParams) red.getLayoutParams()).topMargin += 1;
red.requestLayout();
((ViewGroup.MarginLayoutParams) blue.getLayoutParams()).topMargin -= 1.5;
blue.requestLayout();
text2.setText("" + (int) red.getCameraDistance());
的“text2.setText(‘’= ......”行代码,是我的尝试,试图找出2幅图像之间的距离。但是,没有工作......
你有试过什么吗?刺穿它,看看你得到了什么。 –