Answer the question
In order to leave comments, you need to log in
Android Studio how to implement anchor links in LinearLayout element?
I have a page, it consists of several TextViews inside a LinearLayout tag. How to make a link when clicked on which the screen scrolls to a certain TextView. For example, the first link scrolls the screen to @string/faq01, the second to @string/faq02, and so on.
<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>
Answer the question
In order to leave comments, you need to log in
Hang on TextVew onClickListener, which will scroll to the right place.
Within the framework of xml, without code, you will not solve this problem.
If you want to make it beautiful, you can make your custom View (some kind of LinkedTextView) inherited from TextView. In it, you can store a link to another View to go to, and define the default behavior when clicked.
Then such a View can be assigned a link through an attribute in xml. This approach is very good for reuse, but in general, the implementation will be more complicated than just hanging a listner.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question