作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我拖动 image1 时,它隐藏在 image2 的背景下,我需要在拖动后将 image1 设置在 image2 上。
代码如下: image1.setOnTouchListener(new View.OnTouchListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
@Override
public boolean onTouch(View v, MotionEvent event) {
layoutParams = (LayoutParams) image1.getLayoutParams();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
int x_cord = (int) event.getRawX();
int y_cord = (int) event.getRawY();
if (x_cord > windowwidth) {
x_cord = windowwidth;
}
if (y_cord > windowheight) {
y_cord = windowheight;
}
layoutParams.leftMargin = x_cord - 25;
layoutParams.topMargin = y_cord - 75;
image1.setLayoutParams(layoutParams);
break;
default:
break;
}
return true;
}
});
这是.xml文件
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#888"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:src="@drawable/image" />
</FrameLayout>
最佳答案
我得到了我的答案:
用过这个
image1.bringToFront();
将图像设置在另一个 ImageView 的前面。
关于android - 如何将图像拖到另一个图像背景上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25638200/
我是一名优秀的程序员,十分优秀!