質問

Raw TouchポイントをMonotouchまたはMonodroidの画面座標に翻訳する適切な方法は何ですか?私のコードはエミュレータでうまく機能しますが、ポイントはデバイスでは不正確です。これが私がこれまでに持っているものです:

    private void Initialize()
    {
        this.Touch += TouchView_Touch;
    }

    void TouchView_Touch(object sender, View.TouchEventArgs e)
    {
        e.ReturnValue = true;
        touchPoints.Add(e.Event.RawX);
        touchPoints.Add(e.Event.RawY);
        this.Invalidate();
    }

    protected override void OnDraw(Android.Graphics.Canvas canvas)
    {
        base.OnDraw(canvas);
        canvas.DrawColor(Color.White);
        Paint p = new Paint();
        p.Color = Color.Black;

        Matrix m = new Matrix();
        canvas.GetMatrix(m);
        float[] destination = touchPoints.ToArray();

        Matrix inverse = new Matrix();
        bool canInvert = m.Invert(inverse);
        inverse.MapPoints(destination);

        canvas.DrawPoints(destination, p);
    }
役に立ちましたか?

解決

単調な場合、同じトピックに対処するStackOverFlow Androidの質問がいくつかあります。

ビューの絶対座標を取得する方法

使用を提案します View.GetLocationOnScreen(int[]) また View.GetLocationInWindow().

もあります

Androidのイベント座標とビュー座標の不一致?

これも使用することをお勧めします View.GetLocationOnScreen() デフォルトの表示の画面メトリックを取得するとともに。

他のヒント

Monotouchには、すべてのUIViewsの一部であるConvertPointToviewを使用できます。それはあなたが渡すビューのために、ポイントを正しい座標に変換します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top