Android 通过单击按钮滚动到nestedscrollview中的文本视图

Android 通过单击按钮滚动到nestedscrollview中的文本视图,android,button,scroll,textview,Android,Button,Scroll,Textview,我正在使用滚动活动。我的content_scrolling.xml中没有几个文本视图和按钮,我想在单击特定按钮时通过编程滚动/跳转到特定的文本视图 另外,我不想使用涉及x-y坐标的函数 基本上,我不知道在按钮的OnClick(View v)功能中要做什么 我的内容\u scrolling.xml <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/andr

我正在使用滚动活动。我的content_scrolling.xml中没有几个文本视图和按钮,我想在单击特定按钮时通过编程滚动/跳转到特定的文本视图


另外,我不想使用涉及x-y坐标的函数

基本上,我不知道在按钮的OnClick(View v)功能中要做什么

我的内容\u scrolling.xml

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.admin.test2.ScrollingActivity"
tools:showIn="@layout/activity_scrolling"
android:id="@+id/nsv">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="20dp">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/l1"
        android:paddingLeft="40dp">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="text1"
            android:id="@+id/b1" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="text2"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="text3"
            android:id="@+id/b3" />
    </LinearLayout>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text1"
        android:id="@+id/t1"
        android:textSize="50dp"
        android:paddingTop="40dp"
        android:layout_below="@+id/l1" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text2"
        android:id="@+id/t2"
        android:textSize="50dp"
        android:layout_below="@id/t1"
        android:paddingTop="@dimen/app_bar_height"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text3"
        android:id="@+id/t3"
        android:textSize="50dp"
        android:layout_below="@id/t2"
        android:paddingTop="@dimen/app_bar_height"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>  

尝试使用ScrollView的scrollTo(x,y)方法

your_scrollview.scrollTo(0, your_TextView.getBottom());

您的文本视图是您想要滚动到的文本视图。

“另外,我不想使用涉及x-y坐标的函数。”为什么?!!嗯……我正在寻找一种通用的方法,它可以在我几乎所有的活动中调用……x-y坐标将它限制在特定的活动中。非常感谢。我一直在寻找答案。