gethitRect(),我做错了,请问这是怎么工作的? [英] gethitRect() , I am doing it wrong, how does this work?

查看:115
本文介绍了gethitRect(),我做错了,请问这是怎么工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到上,下,左,右= 0。我想我这样做不对,什么是正确的方法是什么? TIA

在的onCreate()

  ImageView的垃圾=(ImageView的)findViewById(R.id.dropTarget_trash);
    trash.setOnTouchListener(本);
    矩形trashHit =新的矩形();
    trash.getHitRect(trashHit);
    Log.d(TAG,回收站左:+ trashHit.left +右+ trashHit.right +顶+ trashHit.top +底部+ trashHit.bottom);


解决方案

由于命中矩形是在父坐标空间中,家长首先需要布局子,它并没有在没有完成的onCreate()。看看解决方案<一个href=\"http://stackoverflow.com/questions/1343222/is-there-an-example-of-how-to-use-a-touchdelegate-in-android-to-increase-the-size\">here在后运行的一个实例()。如果你有一个自定义视图, getHitRect()的onDraw()会给你正确的尺寸了。

I keep getting top, bottom, left, right = 0. I guess I am doing this wrong, what is the correct way? TIA

in onCreate()

    ImageView trash = (ImageView) findViewById(R.id.dropTarget_trash);
    trash.setOnTouchListener(this);
    Rect trashHit = new Rect();
    trash.getHitRect(trashHit);
    Log.d(TAG,"Trash left:" + trashHit.left + " right: " + trashHit.right + "  top: " + trashHit.top + " bottom: " + trashHit.bottom);

解决方案

As the hit rect is in the parent coordinate space, the parent first needs to layout its children which it hasn't done yet during onCreate(). Take a look at the solution here for an example of running in post(). If you have a custom view, getHitRect() within onDraw() will give you the correct dimensions too.

这篇关于gethitRect(),我做错了,请问这是怎么工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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