2016-08-04 6 views
1

私はスクロールアクティビティを使用しています。私はcontent_scrolling.xmlにTextViewとボタンがほとんどなく、特定のボタンをクリックするとプログラムでスクロール/ジャンプします。ボタンをクリックしてnestedscrollviewのTextviewにスクロールします。

また、私はx-y座標を含む関数を使いたくないです。

基本的には、ボタンのOnClick(View 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

井戸..ほとんどすべての私の活動で呼び出すことができる普遍的な方法を探しています..... xy座標は特定の活動にそれを制限するでしょう –

答えて

1

はScrollViewのscrollTo(x、y)の方法を使用してみてください。

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

your_TextViewはスクロールしたいテキストビューです。

+0

それは働いていません... –