0

i created a scroll view in xml.. i set the height of the scroll view as wrap content ...and i add one linear layout to this scroll view programmaticaly what is my issue is when we add more content to the linear layout i want to focus the last element in the scroll view ?

Here is my code..

<ScrollView
        android:id="@+id/ScrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:background="#ffffff"
        android:fillViewport="true"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:scrollbars="vertical" >

        <LinearLayout
            android:id="@+id/layoutMessage"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/linearLayout1"
            android:layout_weight="1"
            android:background="#ffffff"
            android:orientation="vertical"
             >
        </LinearLayout>



    </ScrollView>
Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143

1 Answers1

7

Simply use this line of code and enjoy after adding the rows in your Linear Layout:

yourScrollView.fullScroll(ScrollView.FOCUS_DOWN);

Also you can use this:

yourScrollView.postDelayed(new Runnable() {
    @Override
    public void run() {
        scroll.fullScroll(ScrollView.FOCUS_DOWN);
    }
}, 600);
mrjimoy_05
  • 3,452
  • 9
  • 58
  • 95
Mohammad Imran
  • 3,264
  • 4
  • 23
  • 37