2012-02-28 7 views
0

Je fais ceci quand j'ai cliqué sur Voir J'essaye d'obtenir la coordination du clic sur la vue. Maintenant, je reçois la valeur dans le monde co-oridates Je veux en locaux Voir les coordonnées vérifier le code ci-dessousConvertir les coordonnées Cliquez sur les coordonnées du monde pour les coordonnées locales?

public void objectClick(View objectClicked) 
    { 

     int [] locationOfViewInWindow=new int[2]; 
     int Object = objectClicked.getId(); 
     View img= (View)findViewById(Object); 
     objectClicked.getLocationInWindow(locationOfViewInWindow); 
     Log.d("Check:","locn in window" + locationOfViewInWindow[0]+ " "+ locationOfViewInWindow[1]); 
     switch (hObject) { 


    case R.id.imageView1: 
      case R.id.imageView2:...... 
        case.R.id.imageview11: 
     ImageView drawable= (ImageView)findViewById(objectClicked.getId()); 
       Drawable d = drawable.getDrawable(); 

      boolean flag = d.getTransparentRegion().contains(locationOfViewInWindow[0], locationOfViewInWindow[1]); 

       Log.d("Check", "Opacity" + flag); 


boolean flag is returning me null because the region of transparent it is checking w.r.t to world co-ordinate 

Suggestion is appreciated 

Répondre

0

Vous devez étendre la classe View pour les objets que vous et utiliser onTouchEvent pour obtenir la position de clic :

public boolean onTouchEvent(MotionEvent event) { 
int eventaction = event.getAction(); 

switch (eventaction) { 
    case MotionEvent.ACTION_DOWN: 
     // finger touches the screen 
     break; 

    case MotionEvent.ACTION_MOVE: 
     // finger moves on the screen 
     break; 

    case MotionEvent.ACTION_UP: 
     // finger leaves the screen 
     break; 
} 

// tell the system that we handled the event and no further processing is required 
return true; 

}

Vous pouvez utiliser event.getX() et event.getY() pour obtenir la position de l'événement tactile.

Questions connexes