简体   繁体   English

SetMovementMethods-带有LinkMovementMethod的ScrollingMovementMethod

[英]SetMovementMethods - ScrollingMovementMethod with LinkMovementMethod

I am new to Android Studio/Java.I have composed a script which creates a TextView contains a number of lines of information. 我是Android Studio / Java的新手,我编写了一个脚本,该脚本创建了一个包含大量信息行的TextView I want to make each line clickable, to create a Toast dialog for example, which content relevant to that entry. 我想使每一行都可单击,以创建一个Toast对话框,例如,与该条目相关的内容。 This I can do. 我能做的

I also want the TextView to be scrollable. 我还希望TextView可滚动。 I can do this too...... but NOT both. 我也可以这样做……但不能两者都做。

I am guessing from what I have read that one command cancels the other. 我从我读到的内容中猜测,一个命令会取消另一个命令。 Here is the code I am trying to use. 这是我尝试使用的代码。 Is there another way to enable this? 还有另一种方法可以启用此功能吗?

responseTextView.setMovementMethod(new ScrollingMovementMethod()); responseTextView.setMovementMethod(LinkMovementMethod.getInstance()); responseTextView.setText(builder, TextView.BufferType.SPANNABLE);

I have found the answer by changing the activity_main.xml to place the TextView inside a ScrollView control. 我已经找到了答案,方法是将activity_main.xml更改为将TextView放置在ScrollView控件中。

<ScrollView android:visibility="visible"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:keepScreenOn="true"
android:scrollbarStyle="insideInset"
android:id="@+id/scrollView1"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnSearch" >

<TextView
    android:id="@+id/lblOutput"
    android:isScrollContainer="true"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbarStyle="outsideOverlay"
    android:scrollbars="vertical"
    android:text="Awaiting Results..."
    android:verticalScrollbarPosition="right"
    android:layout_gravity="top"
    android:keepScreenOn="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btnSearch" />

</ScrollView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM