2012-01-06 17 views
0

これは私がイメージを持っていて、地図の特定のポイントをクリックして他のイメージを表示したいときです。event.getXと画面座標

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#ffffff" 
> 
<ImageView 
    android:id="@+id/map_icon" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:scaleType="fitXY" 
    android:src="@drawable/home_map" /> 

問題は、私はエミュレータ上でそれを実行したときに座標が異なる携帯電話上でそれを実行していると異なっているということです。私は

private void setImageClickListener() { 
    ImageView map_image=(ImageView)findViewById(R.id.map_icon); 
    map_image.setOnTouchListener(new ImageView.OnTouchListener() { 
    //OnTouchListener listener = new OnTouchListener() { 
     public boolean onTouch(View v, MotionEvent event) { 
      if(!(event.getAction() == MotionEvent.ACTION_DOWN)) 
       return false; //If the touch event was not putting the finger down on the screen, return false(Actions may be move, up, and so on) 
      final float x = event.getX(); 
      final float y = event.getY(); 
      System.out.println("Coordinates of button pressed are: X is %d"+x+" and Y is %d"+ y); 
      if(x>260 && x<390 && y>270 && y< 290) 
       DoFirst(); 
      //... and so on... 
      //In the end, you must return a boolean saying whether you "consumed" the event - if you handled the event or not. 
      return true; 
     } 

}); 

と私のxmlファイルがあり、このコードを使用しています。どうすれば複数の画面で実行できますか?私はevent.getXを使って、座標は画像座標を参照し、画面座標は参照しないと考えました。だから私が望むのは、その範囲が画面から独立しているということです。

助けが必要ですか?

+0

3.7インチ私のアプリの作業罰金よりも大きな画面で。私は小さな画面で問題があります。 – ghostrider

答えて

0

ImageViewを完全に制御するためにカスタムビューを使用することをお勧めします。次にonSizeChangeに()を使用すると、正確なサイズどんな携帯を知っているだろう...ここで

は一例です:Make certain area of bitmap transparent on touch

関連する問題