簡體   English   中英

手指拖動摩托羅拉機器人

[英]Finger drag on motorola droid

我正在編寫一個android應用程序,而我的“測試”設備是Motorola Milestone(Droid)。 我做了一個像iPhone主菜單一樣滾動的網格(帶有“點”)。 我遇到兩個問題:

  1. 第一個:拖動僅在Android設備仿真器上有效,而在Droid上無效! (也許多點觸摸屏有問題嗎?)
  2. 拖動操作過於負責,有時會一一翻轉視圖(可以),有時會二乘2或三乘3! 這顯然是有問題的!

這是我的OnTouch方法的代碼:

public boolean onTouch(View v, MotionEvent event) {

    if (v instanceof GridView){
        int eventaction = event.getAction();
        switch (eventaction) {
        case MotionEvent.ACTION_MOVE:
            if (event.getEdgeFlags()==MotionEvent.EDGE_LEFT){
                vf2.setInAnimation(this, R.anim.slide_left);
                vf2.setOutAnimation(this, R.anim.slide_right);
                vf2.showNext();
                if (numCurrentPage==2){
                    numCurrentPage= 0;
                } else {
                    numCurrentPage++;
                }
                notifyPageNumber(numCurrentPage);
            }
            if (event.getEdgeFlags()==MotionEvent.EDGE_RIGHT){
                vf2.setInAnimation(this, R.anim.slide_in);
                vf2.setOutAnimation(this, R.anim.slide_out);
                vf2.showPrevious();
                if (numCurrentPage==0){
                    numCurrentPage= 2;
                } else {
                    numCurrentPage--;
                }
                notifyPageNumber(numCurrentPage);
            }
            break;
        default:
            break;
        }
    }

    return false;
}

謝謝你的幫助!

更新:它在Google Nexus One上不再起作用!

如果您認為正在處理onTouch事件,則應返回true以指示它不應進一步傳播。 如果返回false,則其他偵聽器將收到它並可能對此做出處理,這可能是導致此問題的原因。 如何嘗試:

if (v instanceof GridView){
    ...
    return true;
}
return false;

好的,我設法做到了:

public boolean onTouch(View v, MotionEvent event) {
    if (v instanceof GridView){
        int eventaction = event.getAction();
        switch (eventaction) {
        case MotionEvent.ACTION_DOWN:
            xStart = event.getX();
            break;
        case MotionEvent.ACTION_UP:
            xEnd = event.getX();
            System.out.println("Start = "+xStart+", End = "+xEnd);
            if (xEnd - xStart > 100){

                vf2.setInAnimation(this, R.anim.slide_in);
                vf2.setOutAnimation(this, R.anim.slide_out);
                vf2.showPrevious();
                if (numPageActuelle==0){
                    numCurrentPage= 2;
                } else {
                    numCurrentPage--;
                }
                notifyPageNumber(numCurrentPage);
            }
            if (xEnd - xStart < -100){
                vf2.setInAnimation(this, R.anim.slide_left);
                vf2.setOutAnimation(this, R.anim.slide_right);
                vf2.showNext();
                if (numPageActuelle==2){
                    numCurrentPage= 0;
                } else {
                    numCurrentPage++;
                }
                notifyPageNumber(numCurrentPage);
            }
            return true;
        default:
            break;
        }
        return true;
    }
    return false;
}

現在,我遇到了另一個大問題:我無法單擊網格!

我的網格代碼是:

private ViewFlipper vf;
......
vf.setOnTouchListener(this);
GridView pageGrid = new GridView(this);

pageGrid.setNumColumns(3);
pageGrid.setAdapter(new ModuleAdapter(this,listPages.get(j)));
pageGrid.setOnTouchListener(this);

vf.addView(pageGrid);

我現在不知道如何再次獲得網格上的點擊次數...

如果有人有主意...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM