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

时间:2016-12-15 09:23:22

标签: java android textview gestures

我设法加载了一个可以滚动的文本文件。但是,如何在使用轻击手势滚动时替换拖动手势。这意味着,当我点击左下角的某个位置时,页面将滚动,我不必拖动它来滚动。我目前正在编写android studio。

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());

    }
}

1 个答案:

答案 0 :(得分:0)

管理得出类似的东西,但如果有更好的方法请更新:)

foreach($first_array as $index => $farray)
{
     $second_array[$index]->id = $farray;
}