我有一个页面,它由LinearLayout标记内的多个TextView组成。单击时如何制作链接,在该链接上屏幕滚动到特定的TextView。例如,第一个链接会将屏幕滚动到@ string / faq01,第二个链接将滚动到@ string / faq02,依此类推。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10sp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20sp"
android:text="@string/links"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20sp"
android:text="@string/faq01"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20sp"
android:text="@string/faq02"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20sp"
android:text="@string/faq02"
android:textSize="18sp"/>
</LinearLayout>
您可以使用requestFocus函数以编程方式进行操作。在您的代码中为每个TextView提供ID。每当用户单击Text时,都将requestFocus用于下一个TextView。请参阅示例Kotlin代码:
var link:TextView = findViewById(R.id.tv_firstLink)
link.setOnClickListener({
faq1.requestFocus()
}))