Get effective size of a View object


Last Updated: 2011-05-04 11:46:33
  1. hkproj

    hkproj New Member

    Hi, I have a WebView. I would like to handle those touch who falls into a specific region of the WebView, for example the Rectangle [0, 0, 50, 200]...

    I wrote the following code...

    Code (Text):
    1.  
    2. wvFirst.setOnTouchListener(new OnTouchListener() {
    3.  
    4.     public boolean onTouch(View view, MotionEvent event) { 
    5.                
    6.         Log.i("MyApplication", "Touch at: " + event.getX() + ", " + event.getY());
    7.         return false;
    8.     }
    9.            
    10. });
    11.  
    The problem is that I would like to get the coordinate of the right-most rectangle(X, Y, Width, Height) [Width - 50, 0, 50, Height] of my WebView... but whenever I call the getWidth() or getHeight() I always get zero as result.

    My WebView is declared in the xml:
    HTML:
    1.  
    2. <WebView android:id="@+id/wvFirst" android:layout_width="fill_parent" android:layout_height="fill_parent">
    3. </WebView>
    4.  
    Thank you.

    Advertisement
  2. JordiDroid

    JordiDroid Active Member

Share This Page