限制Android上的触摸次数?

时间:2010-07-26 23:22:44

标签: android multi-touch

我在Android上有一个小测试应用程序,用于测试跟踪多点触控输入,但我只能在我的Evo上同时进行两次触摸。有谁知道这是对Android还是硬件的限制?

顺便说一句,这是我的测试课,所以你可以亲自试试。

import java.util.HashMap;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.MotionEvent;
import android.view.View;

public class PressureView extends View
{
    private HashMap<Integer, Spot> mSpots = new HashMap<Integer, Spot>();
    private final int[] mColors;
    private final Paint mPaint;

    public PressureView(Context context)
    {
        super(context);
        mPaint = new Paint();
        mPaint.setStyle(Style.FILL);
        mColors = new int[]{Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.MAGENTA};
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
        super.onDraw(canvas);

        canvas.drawColor(Color.WHITE);
        for(int id : mSpots.keySet())
        {
            Spot spot = mSpots.get(id);
            mPaint.setColor(spot.Color);
            canvas.drawCircle(spot.X, spot.Y, spot.Pressure*500, mPaint);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        System.out.println("************************** " + event.getPointerCount() + " Pointers");

        for(int i = 0; i < event.getPointerCount(); i++)
        {
            int id = event.getPointerId(i);

            Spot spot = null;
            if(mSpots.containsKey(id))
            {
                spot = mSpots.get(id);
            }
            else
            {
                spot = new Spot();
                spot.Color = mColors[mSpots.size()];
            }

            if(event.getAction() == MotionEvent.ACTION_UP) spot.Pressure = 0;
            else spot.Pressure = event.getPressure(id);

            spot.X = event.getX(id);
            spot.Y = event.getY(id);

            mSpots.put(id, spot);
        }

        invalidate();

        return true;
    }

    private class Spot
    {
        public float X, Y, Pressure;
        public int Color;
    }
}

1 个答案:

答案 0 :(得分:0)

似乎目前所有HTC设备都只能进行2指多点触控,但Android SDK支持更多手指。例如。 Galaxy S i9000支持更多http://www.youtube.com/watch?v=KRCDRXYJBCY