首页 > 解决方案 > 滚动和缩放Textview之间的冲突

问题描述

我对 Textview 有一些问题。我已经为我的应用程序编写了这段代码。如果需要,我希望能够捏一下来缩放和滚动 Textview。我编写了捏缩放的代码,它可以正常工作,但是如果我插入 textview 滚动的代码,它就不起作用,但滚动工作正常。如果我删除滚动代码,我可以通过捏合来缩放,但如果文本对于页面来说太长,我就无法滚动它。我的代码有什么问题?

布局代码:

<TextView
        android:id="@+id/tv_testo_canzone"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="40dp"
        android:layout_marginTop="90dp"
        android:scrollbars="vertical"
        android:text="TextView"
        android:textAlignment="center"
        android:textSize="18sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

主要代码:

tv_testo_canzone = (TextView) findViewById(R.id.tv_testo_canzone);
        tv_titolo = (TextView) findViewById(R.id.tv_titolo_canz);
        tv_artista = (TextView) findViewById(R.id.tv_artista_canz);

        tv_testo_canzone.setMovementMethod(new ScrollingMovementMethod());
linearLayout1 = (RelativeLayout) findViewById(R.id.layout_canzone);

        try {
            reader = new BufferedReader(
                    new InputStreamReader(getAssets().open(nomeTxt)));

            // do reading, usually loop until end of file reading
            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();
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    //log the exception
                }
            }

            tv_testo_canzone.setText((CharSequence) text);

        }

标签: androidtextviewpinchzoom

解决方案


代码没有问题,认为当您使用 ScrollView 时,所有子视图都不会收到手势,因为它们都是由父 ScrollView 处理的


推荐阅读