我在谷歌上搜索了一个关于在同一页面上按 ID 滚动到元素的示例,但没有成功。我想知道如何使用以下示例完成它?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/pressMe"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Press me to scroll to A">
<ImageView
android:id="@+id/scrollToMe"
android:layout_height="100dp"
android:layout_width="fill_parent"
android:layout_marginTop="2000dp"
android:background="#f00">
</LinearLayout>
</ScrollView>
最佳答案
您可以专注于该 View ,我认为它会自动滚动到该 View 。
我相信您还可以获得所需 View 的坐标并滚动到它们。
关于java - Android 在同一页面上滚动到 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11082047/