滚动文本文件时如何用触摸手势替换拖动手势

how to replace drag gesture with touch gesture when scrolling through a text file

我成功加载了一个可以滚动的文本文件。但是,如何在使用点击手势滚动时替换拖动手势。意思是,当我点击左下角的一个点时,页面将滚动,我不必拖动它来滚动。我目前正在 android 工作室编码。

public class MainActivity extends AppCompatActivity {

// private GestureDetector myG;

private StringBuilder text = new StringBuilder();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    BufferedReader reader = null;
    TextView output = (TextView) findViewById(R.id.txtview);
    // myG = new GestureDetector(this,new Gesture());

    try{
        reader = new BufferedReader(new InputStreamReader(getAssets().open("Database Setup.txt")));
        String mLine;
        while ((mLine = reader.readLine()) != null){
            text.append(mLine);
            text.append('\n');
        }
    }catch (IOException e){
        Toast.makeText(getApplicationContext(), "Error reading file!", Toast.LENGTH_LONG).show();
    }finally{
        if (reader != null){
            try{
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        output.setText(text);
        output.setMovementMethod(new ScrollingMovementMethod());

    }
}

设法想出这样的东西,但如果有更好的方法请更新:)

        scrollViewMain.setOnTouchListener(new View.OnTouchListener() {
            float xCoor;
            float yCoor;
            float oldX;
            float oldY;

            View circle = findViewById(R.id.circle);
            long initialTime = 0;
            long endTime = 0;
            @Override
            public boolean onTouch(View v, MotionEvent event) 
            {
                System.out.println("TOUCHED");

                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    if (initialTime == 0) {
                        initialTime = System.currentTimeMillis();
                    } else {
                        endTime = System.currentTimeMillis();
                        diff = endTime - initialTime;
                        initialTime = endTime;

                        xCoor = event.getX();
                        yCoor = event.getY();
                    }

                    if ((diff > 3000)) {

                        circle.setX(oldX);
                        circle.setY(oldY);

                        circle.setVisibility(VISIBLE);
                        oldX = xCoor;
                        oldY = yCoor;
                    } else if (diff < 3000) {
                        circle.setVisibility(View.INVISIBLE);
                        circle.setX(oldX);
                        circle.setY(oldY);
                        oldX = xCoor;
                        oldY = yCoor;
                    }
                    if ((xCoor > 1000) && (yCoor > 1800)){
                        v.scrollBy(0, 300);
                    }

                }
                return false;
            }
        });