如何测试这样的触摸屏

时间:2016-09-20 05:50:12

标签: android swipe gesture-recognition

enter image description here

我想创建一个测试触摸屏的应用,如上图所示。

我创建图片所示布局的代码如下:

private void fillScreen() {
        try {
            for (int i = 1; i < 14; i++) {
                layoutMain = new LinearLayout(getApplicationContext());
                for (int j = 1; j < 14; j++) {
                    b = new Button(getApplicationContext());
                    b.setTag("btn" + i + j);
                b.setBackgroundColor(getResources().getColor(R.color.orange));
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        b.setBackgroundDrawable(getResources().getDrawable(R.drawable.my_button_bg));
                    } else {
                        b.setBackground(getResources().getDrawable(R.drawable.my_button_bg));
                    }
                    b.setOnTouchListener(getOnClickDoSomething(b));

                    b.setLayoutParams(param);
                    layoutMain.addView(b);

                    if (i == j || j == (15 - i - 1) || j == 13 || j == 1 || i == 1 || i == 13) {
                        b.setVisibility(View.VISIBLE);
                    }
                    else {
                        b.setVisibility(View.INVISIBLE);
                    }
                }
                layoutMain.setLayoutParams(layoutParams);
                layoutButtons.addView(layoutMain);
            }
        } catch (Exception e) {
            Log.e("promptMessage,RotationActivity Exception", e.toString());
        }

    }

    View.OnTouchListener getOnClickDoSomething(final Button btn) {
        return new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (!buttons.contains(btn.getTag())) {
                    buttons.add(btn.getTag());
                    btnCounter++;
                }
                btn.setBackgroundColor(getResources().getColor(R.color.videocon_header_green));
                if ((btnCounter) == 67) {
                    flag++;
                    if (flag == 2)
                        promptMessage("Touch Screen test pass?");
                }

                return false;
            }
        };
    }

我可以在触摸时更改按钮的颜色,但我想在屏幕上向右上方滑动手指时更改按钮的颜色&#34;

0 个答案:

没有答案