Android的ontouch例子 [英] Android ontouch example

查看:137
本文介绍了Android的ontouch例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这是我从网上收集的例子。

I have an example which I collect from Internet.

public class MprojectActivity extends Activity {
    /** Called when the activity is first created. */
    ImageView itan2;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        itan2=(ImageView)findViewById(R.id.imageView18);

        itan2.setOnTouchListener( new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub


           if(event.getAction()==MotionEvent.ACTION_MOVE){

               RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) itan2.getLayoutParams();

                    int x =(int)  event.getRawX();
                    int y =(int)  event.getRawY();

                    mParams.leftMargin =  x-236;
                    mParams.topMargin =  y-565;
                    itan2.setLayoutParams(mParams);


           }      
                return true;
            }
        });

                  }

} 

在这个例子中我减去236和565 x和这些价值观actually.how动态编码来找到它们y.What是谁?

In this example I subtract 236 and 565 with x and y.What are these values actually.how to find them with dynamic coding?

推荐答案

这是用于创建相对布局,没有什么复杂的它,它真的很简单。

It is used to create the relative layout, there is nothing complex about it, it's really simple.

X-236表示要设置在x轴上的点236单元远离屏幕的左上角。
Y型565意味着你是从屏幕的左侧顶部设置一个点上y轴565单位了。

x-236 means you are setting a point on x-axis 236 unit away from the left top of the screen. y-565 means you are setting a point on y-axis 565 unit away from the left top of the screen.

通过使用这两个值和左上角的值(0,0)你正在创建一个布局以显示您的图片(这是itan2在这个例子中)

by using those two values and left top value (0,0) you are creating a layout to show your image ( which is itan2 in this example)

这篇关于Android的ontouch例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆