[英]SetMovementMethods - ScrollingMovementMethod with LinkMovementMethod
我是Android Studio / Java的新手,我編寫了一個腳本,該腳本創建了一個包含大量信息行的TextView
。 我想使每一行都可單擊,以創建一個Toast對話框,例如,與該條目相關的內容。 我能做的
我還希望TextView
可滾動。 我也可以這樣做……但不能兩者都做。
我從我讀到的內容中猜測,一個命令會取消另一個命令。 這是我嘗試使用的代碼。 還有另一種方法可以啟用此功能嗎?
responseTextView.setMovementMethod(new ScrollingMovementMethod()); responseTextView.setMovementMethod(LinkMovementMethod.getInstance()); responseTextView.setText(builder, TextView.BufferType.SPANNABLE);
我已經找到了答案,方法是將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.