如何在Android中设置图像移动的边界 [英] How to set boundaries for image move in android
本文介绍了如何在Android中设置图像移动的边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个图像视图,并用OnTouchListener
将其移动了.如何将移动限制在屏幕的边界?
I created an image view and moved it with an OnTouchListener
. How can I limit movement to the boundaries of the screen?
推荐答案
如果要在页面中显示图像,请使用以下代码:
If you want to display an image in the page, use the code below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2px"
android:src="pathOfImage" />
</LinearLayout>
或者您可以使用以下代码设置高度和宽度:
or you can set the hight and width using the code below:
Display display = getWindowManager().getDefaultDisplay();
width = display.getWidth();
height = display.getHeight();
ImageView imageView=(ImageView) findViewById(R.id.image);
imageView.setLayoutParams(new LayoutParams(width, height));
这篇关于如何在Android中设置图像移动的边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文