2016-08-04 36 views
1

我使用的是滾動activity.I在我content_scrolling.xml幾個TextViews和按鈕,我想programmically滾動/跳轉到一個特定的TextView被點擊一個特定的按鈕時。滾動到一個TextView在nestedscrollview通過點擊按鈕

而且,我不希望使用涉及X-Y座標的功能。

基本上,我不知道該怎麼在的OnClick(視圖V)按鈕的功能做。

我content_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> 
+0

「而且,我不希望使用涉及X-Y座標的功能。」爲什麼?!! –

+0

well..i要尋找一個通用的方法,它可以在幾乎所有我的活動..... X-Y座標被稱爲將其限制在一個特定的活動 –

回答

1

嘗試使用滾動型scrollTo的(X,Y)的方法。

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

your_TextView是textview你想滾動到它。

+0

其不工作... –